How to extract a new type alias from an object’s value
const test = {
'a': ['music','bbq','shopping'],
'b': ['move','work']
};
How to get it from a test object
type Types = 'music' | 'bbq' | 'shopping' | 'move' | 'work'
How to extract a new type alias from an object’s value
const test = {
'a': ['music','bbq','shopping'],
'b': ['move','work']
};
How to get it from a test object
type Types = 'music' | 'bbq' | 'shopping' | 'move' | 'work'
2
Answers
You can do this quite easily using
as const
:The only solution I can think of that is not using
as const
is defining an interface with the exact elements of the arrays: