Skip to content

Instantly share code, notes, and snippets.

@dmitriyzyuzin
Created April 5, 2023 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitriyzyuzin/eac2c5f25ff3071acb30b95de13b9bda to your computer and use it in GitHub Desktop.
Save dmitriyzyuzin/eac2c5f25ff3071acb30b95de13b9bda to your computer and use it in GitHub Desktop.
Useful type declarations aka Dimi learn TypeScript :D

Objects

Пусть у нас есть такой объект:

const RADIO_CARD_GROUP_THEME = {
  VERTICAL: 'vertical',
  HORIZONTAL: 'horizontal',
}

Мы можем сделать такие типы:

type KEYS_TYPE = keyof typeof RADIO_CARD_GROUP_THEME; // будет "VERTICAL" | "HORIZONTAL"
type VALUES_TYPE = (typeof RADIO_CARD_GROUP_THEME)[KEYS_TYPE]; // будет 'vertical' | 'horizontal'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment