Typescript : Property does not exist on type 'object'

后端 未结 2 1409
佛祖请我去吃肉
佛祖请我去吃肉 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:33

    You probably have allProviders typed as object[] as well. And property country does not exist on object. If you don't care about typing, you can declare both allProviders and countryProviders as Array:

    let countryProviders: Array;
    let allProviders: Array;
    

    If you do want static type checking. You can create an interface for the structure and use it:

    interface Provider {
        region: string,
        country: string,
        locale: string,
        company: string
    }
    
    let countryProviders: Array;
    let allProviders: Array;
    

提交回复
热议问题