Skip to content

Generics are inferred wrong in a union #56278

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

Closed
awerlogus opened this issue Oct 31, 2023 · 2 comments
Closed

Generics are inferred wrong in a union #56278

awerlogus opened this issue Oct 31, 2023 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@awerlogus
Copy link

🔎 Search Terms

generic union inference

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • 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

https://www.typescriptlang.org/play?ts=5.3.0-dev.20231031#code/CYUwxgNghgTiAEYD2A7AzgF3lAXPAPAKIA08AKgHwAUIAlhgBYgx4DaAZlBGiKYQLrwAPvFYYYAV17l+ASngBeCvABuSWsACwAKB2hIsBMnRYARm07dpmGLRQBzQSLGTpKCQFtTzfjp1QqU1kdIA

💻 Code

declare const a: <E, T>(either: [false, E] | [true, T]) => void

declare const b: [false, string] | [true, number]

// now:      const a: <string, string>(either: [false, string] | [true, string]) => void
// expected: const a: <string, number>(either: [false, string] | [true, number]) => void
a(b)

🙁 Actual behavior

Both parameters: E and T are inferred as strings

🙂 Expected behavior

Parameter E is inferred as a string, parameter T is inferred as a number

Additional information about the issue

No response

@jcalz
Copy link
Contributor

jcalz commented Oct 31, 2023

Possibly related to #45809?

Also looks like #55648 (comment)

@RyanCavanaugh
Copy link
Member

Agree this is duplicate of #45809; tuple and object type discriminants work the same way

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants