1

I'm looking for a way to take a string union type and use it to create a readonly array type basically given the following:

type Params = {
  a: string,
  b: number
}

type ParamKeys = keyof Params

I'd like to get the following type:

Readonly<['a', 'b']>

Is this possible?

Chris Drackett
  • 1,248
  • 2
  • 10
  • 22
  • You're looking to convert a union type (`type ParamKeys = "a" | "b")` to a tuple (`["a" | "b"]`). It _should_ be possible (adapt the solution from https://github.com/microsoft/TypeScript/issues/13298#issuecomment-468114901 and wrap it with `Readonly`), but no built-in solutions yet (e.g. a `tupleof` operator as suggested by the initial GitHub issue. – Anson Miu Apr 08 '21 at 22:17

0 Answers0