[Typescript 4.9] Satisfies operator

type RGB = [number, number, number]

const palette: Record<'red' | 'blue' | 'green', string | RGB> = {
  red: [255, 0, 0],
  green: "#00ff00",
  blue: [0,0,255]
}

palette.red.lastIndexOf(0)
palette.green.toUpperCase()

V4.9:

type RGB = [number, number, number]

const palette = {
  red: [255, 0, 0],
  green: "#00ff00",
  blue: [0,0,255]
} satisfies Record<'red' | 'blue' | 'green', string | RGB>

palette.red.lastIndexOf(0)
palette.green.toUpperCase()

 

posted @ 2022-11-30 15:53  Zhentiw  阅读(12)  评论(0编辑  收藏  举报