0

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.

1 Answer 1

0
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'];

TypeScript Playground

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.