Skip to content

Unions and intersections of readonly properties are now also readonly #9167

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

Merged

Conversation

sandersn
Copy link
Member

Fixes #9108

@ahejlsberg can you take a look to confirm that this is how readonly should work with unions and intersections of properties?

// Unions and intersections of the above
if (symbol.flags & SymbolFlags.SyntheticProperty) {
return forEach(symbol.declarations, decl => isReadonlySymbol(getSymbolOfNode(decl)));
}
Copy link
Member

@ahejlsberg ahejlsberg Jun 14, 2016

Choose a reason for hiding this comment

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

This could probably be more efficient. When a symbol has multiple declarations (such as an overloaded method) we'll end up doing the same check multiple times even though the outcome is always false. Ideally we'd have a SymbolFlags.Readonly that we compute in the same way as SymbolFlags.Optional, but we're out of flag bits. Perhaps it would be better to compute the readonly state in createUnionOrIntersectionProperty (by calling isReadonlySymbol for each underlying symbol) and then record the result in an isReadonly property on the symbol itself.

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 sounds like a good idea. Done.

@sandersn
Copy link
Member Author

@ahejlsberg can you take a look at the updated code?

@mhegazy
Copy link
Contributor

mhegazy commented Jun 24, 2016

👍

@sandersn sandersn merged commit fb3f823 into master Jun 24, 2016
@sandersn sandersn deleted the make-unions-and-intersections-of-readonly-properties-readonly branch June 24, 2016 23:02
@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