简体   繁体   中英

Element implicitly has an 'any' type because index expression is not of type 'number'

I get error below. I know what this code means but I do not know how interface should look like:

Element implicitly has an 'any' type because index expression is not of type 'number'.

interfaces:

export declare interface Category {
    id: string;
    name: string;
    parent_id: string;
}

export declare interface CategoriesMap {
    [key: string]: Category;
}

component:

private listOfSubcategories: CategoriesMap[] = [];

private selectCategory($event: any, index: string) {
        this.category = this.listOfSubcategories[index][$event.target.value];
    }

Regards

Your this.listOfSubcategories is an array, but index is a string. This should be a number to read from the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM