Home > Net >  Typescript - Any of all interface keys as a type
Typescript - Any of all interface keys as a type

Time:09-09

code

What should be the type of name so that the function getValue only allows for one of Data key types as it argument.

CodePudding user response:

Have you tried keyof Data for the name argument? You can do it like

const getValue = (name: keyof Data) => data[name];
  • Related