The object literal property is implicitly of type "any []" - Angular 2

I recently updated angular 2 to a stable version, and suddenly I started getting this error in webpack watcher Object literal property 'avatars' implicitly has an 'any[]' type.Here is the line that gives this error: private selectedContact = {'jcf': {'avatars': [], 'fullname': ''}, meta: []};It gives the same error for meta.

+5
source share
1 answer

With the new typewriter update, new rules and flags come. One of these flags is a flag noImplicitAny. This ensures that you do not initialize the variable as follows:

let avatars = [];

You can either change your own tsconfig.jsonso that you no longer mark this as an error using:

{
    noImplicitAny: false
}

or you can create an interface / class that represents your selectedContact

export interface Contact {
    jcf: ContactDetail;
    meta: any[];
}

And one more interface:

export interface ContactDetail {
    avatars: any[];
    fullname: string;
}

Contact selectedContact:

private selectedContact: Contact = {...};

, , any[]:

let avatars: any[] = [];
+13

Source: https://habr.com/ru/post/1664972/


All Articles