I recently upgraded angular 2 to stable version & suddenly I started getting this error in webpack watcher Object literal's property 'avatars' implicitly has an 'any[]' type.
Here is the line which is giving that error: private selectedContact = {'jcf': {'avatars': [], 'fullname': ''}, meta: []};
Its giving same error for meta
.
With the new typescript update come new rules and flags. One of these flags is the noImplicitAny
flag. This makes sure you don't initialise a variable like this:
let avatars = [];
You can either change your tsconfig.json
to no longer mark this as an error by using:
{
noImplicitAny: false
}
or you can create an interface/class which represents your selectedContact
export interface Contact {
jcf: ContactDetail;
meta: any[];
}
And another interface:
export interface ContactDetail {
avatars: any[];
fullname: string;
}
Now you can assign a Contact interface to your selectedContact property:
private selectedContact: Contact = {...};
Or, which is not very nice, you can explicitly assign it to any[]
:
let avatars: any[] = [];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With