I've got an object like this
const MY_OBJECT = {
'key': 'key val',
'anotherKey': 'anotherKey val',
};
Is there a way to extract from this object 'key' | 'anotherKey'
type ?
I've got an object like this
const MY_OBJECT = {
'key': 'key val',
'anotherKey': 'anotherKey val',
};
Is there a way to extract from this object 'key' | 'anotherKey'
type ?
To get a type that is a union keys of a variable you need to use keyof typeof variableName
.
const MY_OBJECT = {
'key': 'key val',
'anotherKey': 'anotherKey val',
};
type MY_OBJECT_KEYS = keyof typeof MY_OBJECT // "key" | "anotherKey"