-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Typescript 4.2.x - incorrectly infered generic return type of a record union (extra undefined) #43943
Labels
Milestone
Comments
typescript-bot
added
the
Has Repro
This issue has compiler-backed repros: https://aka.ms/ts-repros
label
May 21, 2024
The change between v4.1.5 and v4.2.3 occurred at 22bee77. |
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in the issue body running against the nightly TypeScript. Issue body code block by @TheEdward162 ❌ Failed: -
Historical Information
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
🔎 Search Terms
undefined, generic inference, typescript 4.2
🕗 Version & Regression Information
4.2.0-beta - 4.3.0-dev.20210504 (everything since 4.2 beta, including all stable releases)
NOT in 4.1.x or before
The return type inference of the the arrow function hasn't changed, according to the playground it was always infered as
{ kind: "failure"; value?: undefined; } | { kind: "success"; value: number; }
. However, before 4.2. the type of the generic function above it (theandThen
) was correctly narrowed down toAndThenResult<number>
. This happened even without explicit type annotations, as one would expect.In 4.2+ the undefined gets propagated into
andThen<number | undefined>
and this breaks the assignment (and my expectations).⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The types don't match and the code doesn't compile. The return type of
andThen(fn)
is different than that expected ona
.🙂 Expected behavior
The types do match, the function return type is narrowed to
AndThenResult<number>
and nothing breaks.The text was updated successfully, but these errors were encountered: