Implicitly create a tuple in Typescript

With typescript 3.0, you can have your own utility function:

const tuple = <T extends any[]>(...args: T): T => args

And use it this way:

const tup = tuple(1, 2) // tup type is [number, number]

Leave a Comment