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

Intersection of type parameter and undefined is not never in 4.9 #51041

Closed
dragomirtitian opened this issue Oct 3, 2022 · 1 comment Β· Fixed by #51076
Closed

Intersection of type parameter and undefined is not never in 4.9 #51041

dragomirtitian opened this issue Oct 3, 2022 · 1 comment Β· Fixed by #51076
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@dragomirtitian
Copy link
Contributor

Bug Report

πŸ”Ž Search Terms

intersection never

πŸ•— Version & Regression Information

  • This changed between versions 4.9.0-dev.20220914 and 4.9.0-dev.20220915

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type AB = "A" | "B"

function x<T_AB extends AB>() {
    let r2: never = null! as T_AB & undefined

} 

πŸ™ Actual behavior

The assignment of r2 fails with Type 'T_AB & undefined' is not assignable to type 'never'.. Since T_AB does not contain undefined in its constraint, the intersection should reduce to never (as it did in 4.8)

πŸ™‚ Expected behavior

The assignment should succeed.

@DanielRosenwasser
Copy link
Member

This does not fail though.

type AB = "A" | "B"

function f<T extends AB>(x: T & undefined) {
    let r2: never = x;
} 

I'm not sure how exactly it manifests, but the root cause is likely #50735 since that's the only impactful PR that was merged on the 14th. #50755 came a day before, but likely unrelated.

@DanielRosenwasser DanielRosenwasser added the Needs Investigation This issue needs a team member to investigate its status. label Oct 3, 2022
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.9.2 milestone Oct 3, 2022
@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Oct 3, 2022
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants