Open
Description
Bug Report
π Search Terms
variadic tuple type, rest element, infer, unknown[]
It might be related to #51138 and #51157
π Version & Regression Information
This is the behavior in every version I tried, nightly included.
β― Playground Link
Playground link with relevant code
π» Code
The double inference step is needed to preserve labels of both the first element and the rest.
type HEAD_TAIL<T extends readonly any[]> =
T extends readonly [any?, ...infer TAIL]
?
T extends readonly [...infer HEAD, ...TAIL]
? {
HEAD: HEAD;
TAIL: TAIL;
}
: never
: never;
π Actual behavior
The following is inferred as { HEAD: unknown[]; TAIL: [b: 2, ...c: 3[]]; }
type test3 = HEAD_TAIL<[a:1, b:2, ...c: 3[]]>
π Expected behavior
The expected type is { HEAD: [a:1]; TAIL: [b: 2, ...c: 3[]]; }
.