Is there a way in Typescript to use a known type as the key of an interface, dynamically?
For example, I have this type:
type properties = 'name' | 'age' | 'height';
and I want to allow an object that uses any/all of those "properties" as the key, and a string as the value:
{name: 'abc', height: '2'} or {height: '2'} allowed
I've done this with values, but not keys, so I'd want the opposite of this:
interface person {
[key: string]: properties
}
Something like this:
interface person {
[key: properties]: string
}
type person = { [key in properties]?: string }