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

Destructuring assignment removes undefined from type when default value is given #9422

Conversation

sandersn
Copy link
Member

Fixes #9341

@sandersn
Copy link
Member Author

@mhegazy I think you are the best person to look at this while @ahejlsberg is gone.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 29, 2016

Looks good to me. i would give @ahejlsberg some more time to check it as well.

@sandersn
Copy link
Member Author

Sure. @ahejlsberg do you want to take a look?

// In strict null checking mode, if a default value of a non-undefined type is specified, remove
// undefined from the final type.
if (strictNullChecks &&
!(getCombinedTypeFlags(checkExpressionCached(prop.objectAssignmentInitializer)) & TypeFlags.Undefined)) {
Copy link
Member

Choose a reason for hiding this comment

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

Use checkExpression here, not checkExpressionCached. The latter should only be used (a) when you know that contextual types will never have an effect on the expression and (b) when other checks of the same expression also use the caching version. Neither are true here.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@ahejlsberg
Copy link
Member

👍 Once you make the indicated change.

@mhegazy mhegazy merged commit 07d7ec3 into master Jun 30, 2016
@mhegazy mhegazy deleted the allow-destructuring-assignment-with-default-of-undefined-optional-property branch June 30, 2016 19:41
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants