Skip to content

Prevent merged class/namespace from overlapping with Record<string, unknown> #47088

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
merged 3 commits into from
Jan 7, 2022

Conversation

jakebailey
Copy link
Member

Fixes #43754

If a class is merged with a namespace, we don't want treat values of that type as overlapping with Record<string, unknown>.

Additionally, reformat the expression a little; it was wrapped weirdly and it was not very clear where the parens were (namely, the typeHasCallOrConstructSignatures check appears to be part of the second expression, when it is in fact in the first).

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Dec 9, 2021
: !!(
type.symbol
&& (type.symbol.flags & (SymbolFlags.ObjectLiteral | SymbolFlags.TypeLiteral | SymbolFlags.Enum | SymbolFlags.ValueModule)) !== 0
&& !((type.symbol.flags & SymbolFlags.Class) && (type.symbol.flags & SymbolFlags.ValueModule))
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason not to just use !(type.symbol.flags & SymbolFlags.Class) (dropping the “and is also a value module”)? It looks to me like we believe namespaces generally have an inferable index, and classes don’t, and we want the classiness property to trump the namespacey property in this calculation. It doesn’t seem to need the specificity of “classes merged with namespaces.”

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not; things still work as expected with that simplification. I just took the solution suggested in the issue and thumbs-up'd by Ryan.

Copy link
Member Author

Choose a reason for hiding this comment

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

Switched it over.

@jakebailey jakebailey merged commit 484f141 into microsoft:main Jan 7, 2022
@jakebailey jakebailey deleted the fix-43754 branch January 7, 2022 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team 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.

"sufficiently overlaps" on class instance depends on class statics
3 participants