close

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

Today We are Going To Solve Typescript : Property does not exist on type ‘object’ in javascript. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

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

  1. How to Fix Typescript : Property does not exist on type ‘object’ Error?

    To Fix Typescript : Property does not exist on type ‘object’ Error just Use interface keyable. If there is any key or value pairs are present, then just declare an interface called keyable like given below. interface keyable { [key: string]: any }
    Then use it: let countryProviders: keyable[]; And at the last try it type ProviderKey="region" | "country" | "locale" | "company" let countryProviders: Array<Record<ProviderKey,string>>;

  2. Typescript : Property does not exist on type ‘object’

    To Fix Typescript : Property does not exist on type ‘object’ Error just For allProviders users. If you are using “allProviders” as an array of object, then this will help you. Try given below code to solve your error. I hope this will help you!
    if(providers["country"] === "US") // replacement

Solution 1 : Use interface keyable

If there is any key or value pairs are present, then just declare an interface called keyable like given below.

interface keyable {
    [key: string]: any  
}

Then use it:

let countryProviders: keyable[];

And at the last try it

type ProviderKey="region" | "country" | "locale" | "company"

let countryProviders: Array<Record<ProviderKey,string>>;

Solution 2 : For allProviders users

If you are using “allProviders” as an array of object, then this will help you. Try given below code to solve your error. I hope this will help you!

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

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read This Solutions

Leave a Comment