Typescript - Any of all interface keys as a type

Viewed 15

code

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

1 Answers

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

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