Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- }
Add Comment
Please, Sign In to add comment