Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ycmjason opened this issue Apr 2, 2022 · 1 comment

Comments

@ycmjason
Copy link

@ycmjason ycmjason commented Apr 2, 2022

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
@ycmjason
Copy link
Author

@ycmjason ycmjason commented Apr 2, 2022

Upon further inspection, it looks like removing one of the ... infer would yield correct results.

Playground Link

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

type S = Magic2<[[number]]> // ✅ number
type S2 = Magic2<[[number, 2]]> // ✅ number
type S3 = Magic2<[[number], []]> // ✅ never

/////////

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

type T = Magic3<[[number]]> // ✅ number
type T2 = Magic3<[[number, 2]]> // ✅ never
type T3 = Magic3<[[number], []]> // ✅ number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant