How to make Typescript interface property to be depended on another property

Consider an example:

type Colors = {
  light: 'EC3333' | 'E91515'
  dark: '#100F0F' | '140F0F' 
}

interface Palette {
  colorType: keyof Colors
  color: Colors[keyof Colors]
}

is there any way that type of the color property becomes depended on colorType property?

meaning - when I choose colorType light, color type should become 'EC3333' | 'E91515'



from Recent Questions - Stack Overflow https://ift.tt/3y6jGqZ
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)