Issue
My question is similar with Get all value types of a double-nested object in TypeScript
But the difference is, I want to get union types from the value of a specific property.
const tabsEnum = {
IDCardReview: {
label: 'ID Card',
key: '1',
},
PrescriptionReview: {
label: 'Prescription Review',
key: '2',
}
} as const;
I want to get a union types like type Key = '1' | '2'
. Which means use the value of the key
property in the each object.
Solution
const tabsEnum = {
IDCardReview: {
label: 'ID Card',
key: '1',
},
PrescriptionReview: {
label: 'Prescription Review',
key: '2',
}
} as const;
type Tabs = typeof tabsEnum;
type ValueOf<T> = T[keyof T];
type ValueTabs = ValueOf<Tabs>;
type K = ValueTabs['key'];
Answered By - slideshowp2
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.