0

I'm aware that I can assign a generic to a tuple type based on the input value of a function, for example

declare function example<A extends [any,...any[]]>(a: A) : A
example([1,2,3,[4]]) // : [ number, number, number, number[] ]

However I'd like the literal values, like so

example([1,2,3,[4]]) // : [ 1, 2, 3, [4] ]

How can I achieve this?

Babakness
  • 2,954
  • 3
  • 17
  • 28

1 Answers1

0

This is not possible. When picking a type to instantiate a type variable, Typescript has to choose a single type for A. What you want is to instantiate A with four different types at once.

dimvar
  • 561
  • 5
  • 14