#Get Keys

4 messages · Page 1 of 1 (latest)

sudden summit
#

Is it possible to get the list of id's?

type ColumnsType = { id: string, other: string }

const columns: ColumnsType[] = [
  {
    id: "test",
    other: "lort"
  },
  {
    id: "okay",
    other: "lort"
  }
] as const

type ColumnIds = typeof columns[number]['id']

ColumnIds only shows type ColumnIds = string

raven kraken
#

const columns: ColumnsType[] = ... makes it have exactly that type, and the specific type information is erased.

#

If you do const columns = [...] as const satisfies ColumnsType[] instead, it will still check that it satisfies, without erasing the specific type information.

sudden summit
#

Thx!