1

I have a class Foo and I can obtain the types of its constructor parameters with ConstructorParameters<typeof Foo>.

These parameters are returned as a tuple, say [number, string, string | undefined]. Is it possible to remove the first type from this tuple? I.e. I want the resulting tuple to be [string, string | undefined].

Please note that this must work with any amount of parameters greater than or equal to one.

Lehks
  • 2,582
  • 4
  • 19
  • 50
  • Does this answer your question? [Typescript: Remove entries from tuple type](https://stackoverflow.com/questions/54607400/typescript-remove-entries-from-tuple-type) – rid May 30 '21 at 14:19
  • Take a look at the `RemoveFirstFromTuple` type from [Przemyslaw Jan Beigert's answer to the linked question](https://stackoverflow.com/a/54607819/732284). If `type T = [number, string, string | undefined]` and `type F = RemoveFirstFromTuple`, then `F` becomes `[string, string | undefined]`. – rid May 30 '21 at 14:26

1 Answers1

1

Based on the answers provided by rid, I have constructed the following type, which in my opinion is a bit easier to read than the types provided in his/her answer:

type RemoveFirst<T extends unknown[]> = T extends [infer H, ...infer R] ? R : T;
Lehks
  • 2,582
  • 4
  • 19
  • 50
  • Nice. And it works when `T` is an empty tuple as well, in which case Przemyslaw Jan Beigert's answer returned `undefined`. – rid May 30 '21 at 14:41