David
David

Reputation: 3157

typescript - while not allowing implicit any types

We have chosen not to allow any implicit any types in our project however we are using 3rd party ko.validation libary

We are getting error on the following

ko.validation.rules['minArrayLength'] = {
    validator: function (obj: any, params: any) {
        return obj.length >= params.minLength;
    },
    message: "Array does not meet minimum length requirements"
};

Index signature of object type implicitly has an 'any' type.

The error is on ko.validation.rules['minArrayLength']

How can we not allow any but still use ko.validation.rules?

Upvotes: 2

Views: 232

Answers (1)

David Sherret
David Sherret

Reputation: 106590

Add it to KnockoutValidationRuleDefinitions interface via declaration merging:

interface KnockoutValidationRuleDefinitions {
    minArrayLength: KnockoutValidationRuleDefinition;
}

That will define the rule on ko.validation.rules, thereby removing the implicit any error.

If you are using external modules, make sure to put this interface in your own definition file (.d.ts).

Upvotes: 3

Related Questions