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

Propagate 'undefined' instead of the optional type marker at an optional chain boundary #34588

Merged
merged 3 commits into from
Nov 1, 2019

Conversation

rbuckton
Copy link
Member

This ensures that the optionalType marker type does not escape the boundary of an optional chain. This causes unintended side effects even though optionalType is essentially the same as undefinedType.

Fixes #34579

# Conflicts:
#	src/compiler/utilities.ts
@rbuckton rbuckton requested a review from weswigham October 30, 2019 01:25
src/compiler/types.ts Outdated Show resolved Hide resolved
@@ -45,9 +45,9 @@ const n4: number | undefined = a?.m?.({x: absorb()}); // likewise
>a?.m : (<T>(obj: { x: T; }) => T) | undefined
>a : { m?<T>(obj: { x: T; }): T; } | undefined
>m : (<T>(obj: { x: T; }) => T) | undefined
>{x: absorb()} : { x: number | undefined; }
>x : number | undefined
>absorb() : number | undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting change to inference - I assume this is because previously this undefined was the optional chain type, and so managed to skip out on the "cleave matching types" logic in inference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. The resulting type now aligns with other examples in the file.

Co-Authored-By: Nathan Shively-Sanders <[email protected]>
@rbuckton
Copy link
Member Author

rbuckton commented Nov 1, 2019

@RyanCavanaugh should we cherry-pick this into release-3.7?

@rbuckton rbuckton merged commit ba5e86f into master Nov 1, 2019
@flcdrg
Copy link

flcdrg commented Nov 8, 2019

The issue this PR resolves (#34579) was added to the 3.7.2 milestone https://github.com/microsoft/TypeScript/milestone/106, so I think this should be cherry-picked to 3.7

@RyanCavanaugh
Copy link
Member

@typescript-bot port this to release-3.7

@weswigham
Copy link
Member

weswigham commented Nov 8, 2019

@typescript-bot cherry-pick this to release-3.7 bot reference for reference

@RyanCavanaugh
Copy link
Member

Me bad at bot

typescript-bot pushed a commit to typescript-bot/TypeScript that referenced this pull request Nov 8, 2019
Component commits:
99328e9 Propagate 'undefined' instead of the optional type marker at an optional chain boundary

7aa6eee Merge branch 'master' into fix34579
# Conflicts:
#	src/compiler/utilities.ts

61e6765 Update src/compiler/types.ts
Co-Authored-By: Nathan Shively-Sanders <[email protected]>
@typescript-bot
Copy link
Collaborator

Hey @weswigham, I've opened #34988 for you.

@flcdrg
Copy link

flcdrg commented Nov 8, 2019

Thanks for the quick response 👍

RyanCavanaugh pushed a commit that referenced this pull request Nov 14, 2019
Component commits:
99328e9 Propagate 'undefined' instead of the optional type marker at an optional chain boundary

7aa6eee Merge branch 'master' into fix34579
# Conflicts:
#	src/compiler/utilities.ts

61e6765 Update src/compiler/types.ts
Co-Authored-By: Nathan Shively-Sanders <[email protected]>
@rbuckton rbuckton deleted the fix34579 branch December 16, 2019 22:57
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

Successfully merging this pull request may close these issues.

undefined type from optional chaining doesn't produce correct generic inference candidate from union
6 participants