I don't understand why this code generates TypeScript error. (It's not the original code and is a bit derived, so please ignore the non-sense in the example):
interface Images {
[key:string]: string;
}
function getMainImageUrl(images: Images): string {
return images.main;
}
I'm getting error (using TypeScript 1.7.5):
error TS2339: Property 'main' does not exist on type 'Images'.
Of course I could get rid of the error when writing:
return images["main"];
I'd prefer not using string to access the property. What can I do?
images["main"]
does not throw an error ? – Yassine Badache