Sometimes, we want to fix Property does not exist on type ‘object’ with TypeScript.
In this article, we’ll look at how to fix Property does not exist on type ‘object’ with TypeScript.
How to fix Property does not exist on type ‘object’ with TypeScript?
To fix Property does not exist on type ‘object’ with TypeScript, we can add the missing property to the type that we set for the variable.
For instance, we write
interface Provider {
region: string;
country: string;
locale: string;
company: string;
}
let countryProviders: Array<Provider>;
let allProviders: Array<Provider>;
to create the Provider
interface with the properties that we expect to have in an object with type Provider
and their types.
And then we define variables that has an array type with entries in them being Provider
objects.
Conclusion
To fix Property does not exist on type ‘object’ with TypeScript, we can add the missing property to the type that we set for the variable.