typescript - Index signature of object type implicitly has an 'any' type in Angular 2 official documentation -
i have error when tried implmement reactive form validation of angular 'cookbook' section, can watch on here: https://angular.io/docs/ts/latest/cookbook/form-validation.html#!#reactive
i tried google problem couldn't find solution.
the error code :
index signature of object type implicitly has 'any' type
the following code being used:
onvaluechanged(data?: any) { if (!this.form) { return; } const form = this.form; (const field in this.formerrors) { // clear previous error message (if any) this.formerrors[field] = ''; // sends error code const control = form.get(field); if (control && control.dirty && !control.valid) { const messages = this.validationmessages[field]; // sends error code (const key in control.errors) { this.formerrors[field] += messages[key] + ' '; // sends error code } } } } formerrors = { 'imei': '', 'devicetypeid': '' }; validationmessages = { 'imei': { 'required': 'imei required.', 'minlength': 'imei must @ least 4 characters long.', 'maxlength': 'imei cannot more 24 characters long.', }, 'devicetypeid': { 'required': 'device type required.' } };
i wonder if i'm missing crucial? rest of code similar form validation guide.
you can fix specifying index signature type explicitly. example:
formerrors:{ [key: string] : string; } = { ... }; validationmessages:{ [key: string] : { [key: string] : string; } } = { ... };
if want ignore these errors can specify any
type of mentioned members (e.g formerrors:any
) or use suppressimplicitanyindexerrors compiler option.
Comments
Post a Comment