Skip to content

Nested array incorrectly infer children type to unknown when given a single elementΒ #48524

@ycmjason

Description

@ycmjason

Bug Report

πŸ”Ž Search Terms

nested, infer, inference, unknown

πŸ•— Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Magic<X> = X extends [[infer Y, ...infer _], ...infer _] ? Y : never;

type R = Magic<[[number]]> // ❌ unknown
type R2 = Magic<[[number, 2]]> // βœ… number
type R3 = Magic<[[number], []]> // βœ… number

πŸ™ Actual behavior

  • Magic<[[whatever]]> is unknown

πŸ™‚ Expected behavior

  • Magic<[[whatever]]> should be whatever

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions