Skip to content

Source provides no match for required element at position 0 in target despite source extending [any, ...any[]]Β #48401

Closed
@Roaders

Description

@Roaders

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions