I can't seem to access attributes, see below:
type ValidAttributes = "FOO" | "BAR" | "BAZ";
interface MyInterface {
attributes: {
[s in keyof ValidAttributes]: string;
};
}
const doSomething = (data: MyInterface): void => {
const foo = data.attributes.FOO;
//Error:(10, 31) TS2339: Property 'FOO' does not exist on type '{ toString: string; charAt: string; charCodeAt: string; concat: string; indexOf: string; lastInde...'.
const bar = data.attributes["BAR"];
//Error:(13, 15) TS7017: Element implicitly has an 'any' type because type '{ toString: string; charAt: string; charCodeAt: string; concat: string; indexOf: string; lastInde...' has no index signature.
}
I also have a linter which autocorrects the last code into the other format. This could be disabled if it is the only way.