Closed
Description
Bug Report
🔎 Search Terms
- labeled tuple
- tuple merging
🕗 Version & Regression Information
This is a bug in all versions of Typescript I tested which support labeled tuples, variadic templates and non-last rest parameters in tuples (4.2.x)
⏯ Playground Link
Playground link with relevant code
💻 Code
// Some helpers
type DropFirst<T extends any[]> = T extends [infer _, ...infer T] ? T : never
type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never
// Some setup
type TestFunc = (a: string, b: (x: number, y: string) => void) => void
type TestParams = Parameters<TestFunc>
// Works without a template. Yields [z: Error, y: string]
type TestTypeWorks =
[...[z: Error], ...DropFirst<Parameters<Last<TestParams>>>]
// Breaks when used with a template? Yields [Error, string]
type TestTypeTpl<T extends [...any[], (...args: any) => any]> =
[...[z: Error], ...DropFirst<Parameters<Last<T>>>]
type TestTypeFails = TestTypeTpl<TestParams>
// Individual pieces work fine
// Yields [y: string]
type TestTypeTpl2<T extends [...any[], (...args: any) => any]> =
[...DropFirst<Parameters<Last<T>>>]
type TestTypeWorksX = TestTypeTpl2<TestParams>
// Yields [z: Error]
type TestTypeTpl3<_ extends [...any[], (...args: any) => any]> =
[...[z: Error]]
type TestTypeWorksY = TestTypeTpl3<TestParams>
// But then they fail again when we put them together. Yields [Error, string]
type TestTypeFailsTpl4<T extends [...any[], (...args: any) => any]> =
[...TestTypeTpl2<T>, ...TestTypeTpl3<T>]
type TestTypeWorksZ = TestTypeFailsTpl4<TestParams>
🙁 Actual behavior
The tuples lost their labels.
🙂 Expected behavior
The tuples should still have their labels.