Skip to content

Commit a7d7a4c

Browse files
committed
Use first declaration, not valueDeclaration
valueDeclaration is frequently not set
1 parent 0913ef6 commit a7d7a4c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8955,7 +8955,7 @@ namespace ts {
89558955
reportError(Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target));
89568956
}
89578957
else {
8958-
const objectLiteralDeclaration = source.symbol && source.symbol.valueDeclaration;
8958+
const objectLiteralDeclaration = source.symbol && firstOrUndefined(source.symbol.declarations);
89598959
if (prop.valueDeclaration && findAncestor(prop.valueDeclaration, d => d === objectLiteralDeclaration)) {
89608960
errorNode = prop.valueDeclaration;
89618961
}

tests/baselines/reference/objectSpreadNegative.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(52,9): error TS2339
1717
tests/cases/conformance/types/spread/objectSpreadNegative.ts(57,11): error TS2339: Property 'a' does not exist on type '{}'.
1818
tests/cases/conformance/types/spread/objectSpreadNegative.ts(61,14): error TS2698: Spread types may only be created from object types.
1919
tests/cases/conformance/types/spread/objectSpreadNegative.ts(64,14): error TS2698: Spread types may only be created from object types.
20-
tests/cases/conformance/types/spread/objectSpreadNegative.ts(78,7): error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'.
20+
tests/cases/conformance/types/spread/objectSpreadNegative.ts(78,37): error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'.
2121
Object literal may only specify known properties, and 'extra' does not exist in type 'A'.
2222
tests/cases/conformance/types/spread/objectSpreadNegative.ts(81,7): error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'.
2323
Object literal may only specify known properties, and 'extra' does not exist in type 'A'.
@@ -139,7 +139,7 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(83,7): error TS2322
139139
type A = { a: string, b: string };
140140
type Extra = { a: string, b: string, extra: string };
141141
const extra1: A = { a: "a", b: "b", extra: "extra" };
142-
~~~~~~
142+
~~~~~~~~~~~~~~
143143
!!! error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'.
144144
!!! error TS2322: Object literal may only specify known properties, and 'extra' does not exist in type 'A'.
145145
const extra2 = { a: "a", b: "b", extra: "extra" };

0 commit comments

Comments
 (0)