@@ -5881,7 +5881,7 @@ namespace ts {
5881
5881
* this function should be called in a left folding style, with left = previous result of getSpreadType
5882
5882
* and right = the new element to be spread.
5883
5883
*/
5884
- function getSpreadType(left: Type, right: Type, symbol: Symbol ): ResolvedType | IntrinsicType {
5884
+ function getSpreadType(left: Type, right: Type, isFromObjectLiteral: boolean ): ResolvedType | IntrinsicType {
5885
5885
Debug.assert(!!(left.flags & (TypeFlags.Object | TypeFlags.Any)) && !!(right.flags & (TypeFlags.Object | TypeFlags.Any)), "Only object types may be spread.");
5886
5886
if (left.flags & TypeFlags.Any || right.flags & TypeFlags.Any) {
5887
5887
return anyType;
@@ -5900,14 +5900,14 @@ namespace ts {
5900
5900
numberIndexInfo = unionSpreadIndexInfos(getIndexInfoOfType(left, IndexKind.Number), getIndexInfoOfType(right, IndexKind.Number));
5901
5901
}
5902
5902
5903
- const isFromSpread = right.symbol !== symbol;
5904
5903
for (const rightProp of getPropertiesOfType(right)) {
5904
+ // we approximate own properties as non-methods plus methods that are inside the object literal
5905
+ const isOwnProperty = !(rightProp.flags & SymbolFlags.Method) || isFromObjectLiteral;
5906
+ const isSetterWithoutGetter = rightProp.flags & SymbolFlags.SetAccessor && !(rightProp.flags & SymbolFlags.GetAccessor);
5905
5907
if (getDeclarationModifierFlagsFromSymbol(rightProp) & (ModifierFlags.Private | ModifierFlags.Protected)) {
5906
5908
skippedPrivateMembers[rightProp.name] = true;
5907
5909
}
5908
- else if (!(rightProp.flags & SymbolFlags.Method && isFromSpread) &&
5909
- !(rightProp.flags & SymbolFlags.SetAccessor && !(rightProp.flags & SymbolFlags.GetAccessor))) {
5910
- // skip methods from spreads and accessors with setters but no getters
5910
+ else if (isOwnProperty && !isSetterWithoutGetter) {
5911
5911
members[rightProp.name] = rightProp;
5912
5912
}
5913
5913
}
@@ -5937,7 +5937,7 @@ namespace ts {
5937
5937
members[leftProp.name] = leftProp;
5938
5938
}
5939
5939
}
5940
- return createAnonymousType(symbol , members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
5940
+ return createAnonymousType(undefined , members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
5941
5941
}
5942
5942
5943
5943
function createLiteralType(flags: TypeFlags, text: string) {
@@ -10947,7 +10947,7 @@ namespace ts {
10947
10947
}
10948
10948
else if (memberDecl.kind === SyntaxKind.SpreadAssignment) {
10949
10949
if (propertiesArray.length > 0) {
10950
- spread = getSpreadType(spread, createObjectLiteralType(), node.symbol );
10950
+ spread = getSpreadType(spread, createObjectLiteralType(), /*isFromObjectLiteral*/ true );
10951
10951
propertiesArray = [];
10952
10952
propertiesTable = createMap<Symbol>();
10953
10953
hasComputedStringProperty = false;
@@ -10959,7 +10959,7 @@ namespace ts {
10959
10959
error(memberDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
10960
10960
return unknownType;
10961
10961
}
10962
- spread = getSpreadType(spread, type, node.symbol );
10962
+ spread = getSpreadType(spread, type, /*isFromObjectLiteral*/ false );
10963
10963
continue;
10964
10964
}
10965
10965
else {
@@ -11003,9 +11003,10 @@ namespace ts {
11003
11003
11004
11004
if (spread !== emptyObjectType) {
11005
11005
if (propertiesArray.length > 0) {
11006
- spread = getSpreadType(spread, createObjectLiteralType(), node.symbol );
11006
+ spread = getSpreadType(spread, createObjectLiteralType(), /*isFromObjectLiteral*/ true );
11007
11007
}
11008
11008
spread.flags |= propagatedFlags;
11009
+ spread.symbol = node.symbol;
11009
11010
return spread;
11010
11011
}
11011
11012
0 commit comments