close

[Solved] Typescript : Property does not exist on type ‘object’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Typescript : Property does not exist on type ‘object’ in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Typescript : Property does not exist on type ‘object’ Error Occurs?

Today I get the following error Typescript : Property does not exist on type ‘object’ in javascript.

How To Solve Typescript : Property does not exist on type ‘object’ Error ?

  1. How To Solve Typescript : Property does not exist on type 'object' Error ?

    To Solve Typescript : Property does not exist on type 'object' Error the above methods are highly recommended, but if you have no choice and want to continue using “allProviders” as an array of object, then go for this method. This worked for me without creating an interface.

  2. Typescript : Property does not exist on type 'object

    To Solve Typescript : Property does not exist on type 'object' Error the above methods are highly recommended, but if you have no choice and want to continue using “allProviders” as an array of object, then go for this method. This worked for me without creating an interface

Solution 1

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<any>:

let countryProviders: Array<any>;
let allProviders: Array<any>;

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<Provider>;
let allProviders: Array<Provider>;

Solution 2

Yes the above methods are highly recommended, but if you have no choice and want to continue using “allProviders” as an array of object, then go for this method. This worked for me without creating an interface.

if(providers["country"] === "US") // replacement

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment