-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Set symbol on union that is returned from getSpreadType
#18965
Conversation
Previously, it was only set on the top-level type, and only if that top-level type was an object type. Now it uses `forEachType` to set the symbol on every object type in the union as well, if `getSpreadType` returns a union.
Also tighten up the existing test code in the file.
src/compiler/checker.ts
Outdated
t.flags |= propagatedFlags; | ||
t.flags |= TypeFlags.FreshLiteral; | ||
(t as ObjectType).objectFlags |= ObjectFlags.ObjectLiteral; | ||
t.symbol = node.symbol; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this trample over the existing symbol on any object types spread (should one be present)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead pass this symbol to getSpreadType and avoid the mutation after creating the type..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weswigham In its current state getSpreadType + the emptyObjectType check above will never trample an existing type. However, @mhegazy's idea is much less error-prone for future changes. Right now, getSpreadType is only called from places that have a symbol on hand anyway, since it's not a real type operator like it was planned to be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. It caused some churn in the ad-hoc JSX code, but it's probably worth it for the readability in checkObjectLiteral.
Previously, getSpreadType didn't set any flags and relied on its callers to do so. This was error-prone because getSpreadType often returns non-fresh types.
Fixes #16694
Previously, it was only set on a top-level type resulting from
getSpreadType
, and only if that top-level type was an object type. NowcheckObjectLiteral
usesforEachType
to set the symbol on every object type in the union as well, ifgetSpreadType
returns a union.