Closed
Description
Bug Report
π Search Terms
tuple, conditional type
π Version & Regression Information
4.6.2
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Conditional Types
β― Playground Link
Playground link with relevant code
π» Code
type RecursiveType<TList extends [any, ...any[]]> = ((
...list: TList
) => unknown) extends (h: infer Head, ...tail: infer Tail) => unknown
? ((h: Head) => unknown) extends (h: Array<infer R>) => unknown
? R
: ((h: Head, ...tail: Tail) => unknown) extends (
h: any,
...tail: [any, ...any[]] // ensure that Tail extends [any, ...any[]]
) => unknown
? RecursiveType<Tail> // Error: Source provides no match for required element at position 0 in target
: unknown
: unknown;
π Actual behavior
Comile error:
Error: Source provides no match for required element at position 0 in target
π Expected behavior
We should be able to pass Tail
back into RecursiveType
as we are ensuring that Tail
extends [any, ...any[]]
. I have tried this a few different ways, by re-inferring the type of the tail and by switching the Tail
and [any, ...any[]]
around so we check that [any, ...any[]]
extends Tail
instead.