Guest User

Untitled

a guest
Apr 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. type ValidAttributes = "FOO" | "BAR" | "BAZ";
  2.  
  3. interface MyInterface {
  4. attributes: {
  5. [s in keyof ValidAttributes]: string;
  6. };
  7. }
  8.  
  9. const doSomething = (data: MyInterface): void => {
  10. const foo = data.attributes.FOO;
  11. //Error:(10, 31) TS2339: Property 'FOO' does not exist on type '{ toString: string; charAt: string; charCodeAt: string; concat: string; indexOf: string; lastInde...'.
  12.  
  13. const bar = data.attributes["BAR"];
  14. //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.
  15. }
Add Comment
Please, Sign In to add comment