只是为了说明我认为 Steve 已经说过的话,如果您从 DeveloplyTyped 下载 d.ts,然后打开文件,您将看到Validator
界面(以及其他定义)。扩展它很简单:
interface Validator {
format(template: string, ...arguments: string[]): string;
form(): bool;
element(element: any): bool;
resetForm(): void;
showErrors(errors: any): void;
numberOfInvalids(): number;
setDefaults(defaults: ValidationOptions): void;
addMethod(name: string, method: (value: any, element: any, ...params: any[]) => any, message?: any): void;
addClassRules(rules: any): void;
addClassRules(name: string, rules: any): void;
// Just add the unobtrusive element to this (typed as `any` if you don't have time to do anything more)
unobtrusive:any;
}
JQuery
扩展和接口的其余工作JQueryStatic
已经在文件的其他地方为您完成。你不会在unobtrusive
元素上得到任何类型的好处,但至少所有其余的Validator
代码都会被类型检查。