Skip to content

Commit b394182

Browse files
committed
Improve excess property check for spread property
Fall back to the assignment's declaration; don't use the property's valueDeclaration because that is not useful when the property comes from a spread. The fallback now happens when the property's valueDeclaration does not have the object literal's valueDeclaration as an ancestor.
1 parent f4298f1 commit b394182

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8955,7 +8955,8 @@ namespace ts {
89558955
reportError(Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target));
89568956
}
89578957
else {
8958-
if (prop.valueDeclaration) {
8958+
const objectLiteralDeclaration = source.symbol && source.symbol.valueDeclaration;
8959+
if (prop.valueDeclaration && findAncestor(prop.valueDeclaration, d => d === objectLiteralDeclaration)) {
89598960
errorNode = prop.valueDeclaration;
89608961
}
89618962
reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1,

0 commit comments

Comments
 (0)