4

How do I get the type of values from an object as a tuple of those types?

type Obj = { a: true, b: 1 }
type ValueTuple<T extends object> = ???
type Test = ValueTuple<Obj> // [true, 1]
Jacob
  • 1,642
  • 2
  • 15
  • 27
  • 1
    There are ways to do this but I would advise against it. What you want is basically to turn a union into a tuple, which is a strange operation, since the tuple is inherently unordered while the tuple is ordered. There is a long gh thread about this https://github.com/Microsoft/TypeScript/issues/13298 – Titian Cernicova-Dragomir Apr 28 '19 at 12:53
  • 1
    I meant a union is unordered, while the tuple is ordered. Too late to edit.. – Titian Cernicova-Dragomir Apr 28 '19 at 12:59

1 Answers1

4

I don't think that you can get values as types. Even if you could, this is a bad idea. This previously answered question, How to transform union type to tuple type is a far better answer than I could give :)

Daniel Cottone
  • 4,257
  • 24
  • 39