У меня есть типизация для jquery и jquery.validation, но stil получить ошибку в $ (this).closest("form"). Valid() Свойство 'valid' не существует для значения типа 'JQuery' Есть ли типизация Мне не хватает? благодаря
Я посмотрел в файле определения и мог видеть Valid: boolean, но не работал бы независимо от того, сколько раз я скомпилировал или повторил визуальную студию. Сегодня утром после повторной визуальной студийной ошибки ушло спасибо.
Помогите себе исправить:
interface JQuery{
valid:any;
}
Используйте это определение: https://github.com/borisyankov/DefinitelyTyped/blob/master/jquery.validation/jquery.validation.d.ts
Важные разделы этого определения (Не копируйте пасту... просто указывая на усилия сообщества)
interface JQuery
{
/**
* Remove the specified attributes from the first matched element and return them.
*
* @param attributes A space-seperated list of attribute names to remove.
*/
removeAttrs(attributes: string): any;
/**
* Returns the validations rules for the first selected element
*/
rules(): any;
/**
* Removes the specified rules and returns all rules for the first matched element.
*
* @param command "remove"
* @param rules Removes and returns all rules. Manipulates only rules specified via rules-option or via rules("add").
*/
rules(command: string): any;
/**
* Removes the specified rules and returns all rules for the first matched element.
*
* @param command "remove"
* @param rules The space-separated names of rules to remove and return. Manipulates only rules specified via rules-option or via rules("add").
*/
rules(command: string, rules: string): any;
/**
* Adds the specified rules and returns all rules for the first matched element. Requires that the parent form is validated, that is, $("form").validate() is called first
*
* @param command "add"
* @param rules The rules to add. Accepts the same format as the rules-option of the validate-method.
*/
rules(command: string, rules: Object): any;
/**
* Checks whether the selected form is valid or whether all selected elements are valid.
*/
valid(): boolean;
/**
* Validates the selected form.
*
* @param options options for validation
*/
validate(options?: ValidationOptions): Validator;
}
Вы должны использовать определение для каждой используемой библиотеки.
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.12.0/jquery.validate.js"></script>
после включения библиотеки jQuery