< Back to list

TypeScript

JS

Any Object Key
type Test = {
  [key: string]: any;
}
Get Type of Child Key
type Test = {
  a: string
}

type NewTest = Test["a"] // string
Tuple to Union
type Test = ["test", "test2"]

type NewTest = Test[number] // "test" | "test2"