Skip to content

Make literal types not comparable to weak object types without property overlap #49865

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Aug 16, 2022

Conversation

andrewbranch
Copy link
Member

Previously, a type "A" was comparable with type { weak?: boolean } because we don’t do common property checks for comparability. That leads to poor narrowing behavior in unions between these types. This PR allows common property checks for comparability to proceed if the source is a literal type.

Fixes #48858

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Jul 11, 2022
@andrewbranch
Copy link
Member Author

@typescript-bot test this
@typescript-bot user test this inline
@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 11, 2022

Heya @andrewbranch, I've started to run the extended test suite on this PR at fccbbe8. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 11, 2022

Heya @andrewbranch, I've started to run the diff-based user code test suite on this PR at fccbbe8. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 11, 2022

Heya @andrewbranch, I've started to run the parallelized Definitely Typed test suite on this PR at fccbbe8. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

@andrewbranch
Great news! no new errors were found between main..refs/pull/49865/merge

@typescript-bot
Copy link
Collaborator

Heya @andrewbranch, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

@andrewbranch andrewbranch added the Breaking Change Would introduce errors in existing code label Jul 12, 2022
@andrewbranch
Copy link
Member Author

Unless @DanielRosenwasser has some reason to object, we might want to hold this until 4.9 to be safe. The existing behavior is long-standing and this could turn up new errors in comparisons.

@andrewbranch andrewbranch merged commit 4e33e0e into microsoft:main Aug 16, 2022
@andrewbranch andrewbranch deleted the bug/48858 branch August 16, 2022 00:10
RyanCavanaugh added a commit to RyanCavanaugh/coc.nvim that referenced this pull request Aug 29, 2022
Change function type to indicate that `true` is also a possible input value. This was found by TypeScript 4.9

See microsoft/TypeScript#49865
chemzqm pushed a commit to neoclide/coc.nvim that referenced this pull request Aug 30, 2022
Change function type to indicate that `true` is also a possible input value. This was found by TypeScript 4.9

See microsoft/TypeScript#49865
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Author: Team Breaking Change Would introduce errors in existing code For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Object literal types with only optional properties break control flow narrowing
3 participants