Typescript : Property does not exist on type 'object'

后端 未结 2 1411
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-31 13:42

I have the follow setup and when I loop through using for...of and get an error of :

Property "country" doesn\'t exist on type "o

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 14:39

    If your object could contain any key/value pairs, you could declare an interface called keyable like :

    interface keyable {
        [key: string]: any  
    }
    

    then use it as follows :

    let countryProviders: keyable[];
    

    or

    let countryProviders: Array;
    

提交回复
热议问题