To fix error TS2339: Property ‘x’ does not exist on type ‘Y’ with TypeScript, we need to define the property in the interface with the right type.
For instance, we write
interface Images {
main: string;
[key: string]: string;
}
const getMain = (images: Images): string => {
return images.main;
};
to define the Images interface with the main property.
Then we can get the value of the images.main property without an error since the Images interface has the main property and it’s a string.
If the property name and its type matches, then the error should go away.