typescript compiler bug? knockout.validation.d.ts doesn't compile anymore

前端 未结 1 595
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-07 04:21

I just updated Typescript from v2.3 to v2.4, and now it is giving me an error on the knockout.validation.d.ts lines:

interface KnockoutSubscribableFunctions

        
相关标签:
1条回答
  • 2021-02-07 04:44

    The problem exists because of differences in types of the:

    [key: string]: KnockoutBindingHandler;
    

    And other params:

    isValid: KnockoutComputed<boolean>;
    isValidating: KnockoutObservable<boolean>;
    rules: KnockoutObservableArray<KnockoutValidationRule>;
    isModified: KnockoutObservable<boolean>;
    error: KnockoutComputed<string>;
    setError(error: string): void;
    clearError(): void;
    

    The error you got basically says: the KnockoutComputed type can't be assigned to the KnockoutBindingHandler type.

    Probably this compile-time checking are improved in TS 2.4, that's why you hadn't had this problem previously.

    Your solution works:

    [key: string]: any;//KnockoutBindingHandler;
    

    And if you can change this code you may try another a little bit "prettier" solution:

    [key: string]: any | KnockoutBindingHandler;
    

    Which might provide you some additional autocomplete help.

    0 讨论(0)
提交回复
热议问题