Don't include class getter in spread type - #26287
Conversation
718e66b to
7dded40
Compare
Nathan Shively-Sanders (sandersn)
left a comment
There was a problem hiding this comment.
Looks good. Just a couple of small cleanup items.
| } | ||
|
|
||
| function isSpreadableProperty(prop: Symbol): boolean { | ||
| // We approximate own properties as non-methods plus methods that are inside the object literal |
There was a problem hiding this comment.
Comment should be jsdoc.
| const isPrivate = getDeclarationModifierFlagsFromSymbol(prop) & (ModifierFlags.Private | ModifierFlags.Protected); | ||
| const isSetOnlyAccessor = prop.flags & SymbolFlags.SetAccessor && !(prop.flags & SymbolFlags.GetAccessor); | ||
| if (!inNamesToRemove && !isPrivate && !isClassMethod(prop) && !isSetOnlyAccessor) { | ||
| if (!names.has(prop.escapedName) && !(getDeclarationModifierFlagsFromSymbol(prop) & (ModifierFlags.Private | ModifierFlags.Protected)) && isSpreadableProperty(prop)) { |
There was a problem hiding this comment.
It would be nice to wrap this line. It’s not readable on github’s default style sheet.
| // We approximate own properties as non-methods plus methods that are inside the object literal | ||
| return prop.flags & (SymbolFlags.Method | SymbolFlags.GetAccessor) | ||
| ? !prop.declarations.some(decl => isClassLike(decl.parent)) | ||
| : !(prop.flags & SymbolFlags.SetAccessor); // Setter without getter is not spreadable |
There was a problem hiding this comment.
A Setter is actually spreadable and results in undefined:
({
foo: 1,
...{set foo(v) {}}
}).foo === undefined;There was a problem hiding this comment.
Can you open a new issue for that? It’s different from skipping things that come from classes.
There was a problem hiding this comment.
Will do. It seemed to me like this condition was added in this PR
There was a problem hiding this comment.
No, I thought so too, but it's just adding accessors to the list of things that are skipped when they come from a class declaration.
* origin/master: (283 commits) Don't error on destructure of private property with computed property syntax (microsoft#26360) getDefaultExportInfo: Use `getImmediateAliasedSymbol` instead of `getAliasedSymbol` (microsoft#26364) review comments restore old algorithm Dont use baseURL relative absolute paths in declaration emit, use absolute paths in bundle emit (microsoft#26341) Update user baselines (microsoft#26358) Don't store @template constraint in a TypeParameterDeclaration node (microsoft#26283) fixAddMissingMember: Support interface and don't crash on type parameter (microsoft#25995) Don't include class getter in spread type (microsoft#26287) Don't crash on computed property in destructure (microsoft#26334) Check the ambientness of a symbol name before attempting to trim it (microsoft#26312) Still generate signatures in SkipContextSensitive mode just to match on return types (microsoft#25937) fix handling if there is no commonPrefix Actually add sorting of elaboration text to user baselines Ping ryan instead of mohammed for user PRs now handle failed lookups make it work for root directory really, really fix test(?) add test fix commonPrefix handling ...
Fixes #26279