From a7d7a4cedfa66dfa849b9463bd037c9f14ef8019 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 14 Jun 2017 11:43:51 -0700 Subject: [PATCH] Use first declaration, not valueDeclaration valueDeclaration is frequently not set --- src/compiler/checker.ts | 2 +- tests/baselines/reference/objectSpreadNegative.errors.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4f68f19c617..538a80e955a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8955,7 +8955,7 @@ namespace ts { reportError(Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target)); } else { - const objectLiteralDeclaration = source.symbol && source.symbol.valueDeclaration; + const objectLiteralDeclaration = source.symbol && firstOrUndefined(source.symbol.declarations); if (prop.valueDeclaration && findAncestor(prop.valueDeclaration, d => d === objectLiteralDeclaration)) { errorNode = prop.valueDeclaration; } diff --git a/tests/baselines/reference/objectSpreadNegative.errors.txt b/tests/baselines/reference/objectSpreadNegative.errors.txt index 1a8df3ed74c..a9381a0dcb1 100644 --- a/tests/baselines/reference/objectSpreadNegative.errors.txt +++ b/tests/baselines/reference/objectSpreadNegative.errors.txt @@ -17,7 +17,7 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(52,9): error TS2339 tests/cases/conformance/types/spread/objectSpreadNegative.ts(57,11): error TS2339: Property 'a' does not exist on type '{}'. tests/cases/conformance/types/spread/objectSpreadNegative.ts(61,14): error TS2698: Spread types may only be created from object types. tests/cases/conformance/types/spread/objectSpreadNegative.ts(64,14): error TS2698: Spread types may only be created from object types. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(78,7): error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(78,37): error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'. Object literal may only specify known properties, and 'extra' does not exist in type 'A'. tests/cases/conformance/types/spread/objectSpreadNegative.ts(81,7): error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'. 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 type A = { a: string, b: string }; type Extra = { a: string, b: string, extra: string }; const extra1: A = { a: "a", b: "b", extra: "extra" }; - ~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'. !!! error TS2322: Object literal may only specify known properties, and 'extra' does not exist in type 'A'. const extra2 = { a: "a", b: "b", extra: "extra" };