1
我想使用Typescript为Knockout-Validation库(https://github.com/Knockout-Contrib/Knockout-Validation)编写自定义规则。我有一个的.ts文件,我想了这个代码:Typescript敲除验证自定义规则
export function enableCustomValidators() {
ko.validation.rules["myRule"] = {
validator: function (val: string, otherVal: string) {
return val === otherVal;
},
message: 'The field must equal {0}',
}
ko.validation.registerExtenders();
}
在构建时,我收到此错误:错误TS7017元素隐含有一个“任意”类型,因为类型“KnockoutValidationRuleDefinitions”没有索引签名。
使用Typescript添加新的自定义验证程序的正确方法是什么?
感谢