From 0913ef66e6f6a7fe06a6f291bb925bfc4dfaf172 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 14 Jun 2017 11:29:06 -0700 Subject: [PATCH] Test:error span for spread prop in excess prop check --- .../reference/objectSpreadNegative.errors.txt | 27 ++++++++++++++++++- .../reference/objectSpreadNegative.js | 16 +++++++++++ .../types/spread/objectSpreadNegative.ts | 10 +++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/objectSpreadNegative.errors.txt b/tests/baselines/reference/objectSpreadNegative.errors.txt index d9106d651a3..1a8df3ed74c 100644 --- a/tests/baselines/reference/objectSpreadNegative.errors.txt +++ b/tests/baselines/reference/objectSpreadNegative.errors.txt @@ -17,9 +17,15 @@ 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'. + 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'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(83,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'. -==== tests/cases/conformance/types/spread/objectSpreadNegative.ts (16 errors) ==== +==== tests/cases/conformance/types/spread/objectSpreadNegative.ts (19 errors) ==== let o = { a: 1, b: 'no' } /// private propagates @@ -128,4 +134,23 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(64,14): error TS269 f({ a: 1 }, { a: 'mismatch' }) let overwriteId: { id: string, a: number, c: number, d: string } = f({ a: 1, id: true }, { c: 1, d: 'no' }) + + // excess property checks + 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" }; + const a1: A = { ...extra1 }; // error spans should be here + const a2: A = { ...extra2 }; // not on the symbol declarations above + ~~ +!!! 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 extra3: Extra = { a: "a", b: "b", extra: "extra" }; + const a3: A = { ...extra3 }; // same here + ~~ +!!! 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'. \ No newline at end of file diff --git a/tests/baselines/reference/objectSpreadNegative.js b/tests/baselines/reference/objectSpreadNegative.js index fd834b6ef9c..0cc93692b59 100644 --- a/tests/baselines/reference/objectSpreadNegative.js +++ b/tests/baselines/reference/objectSpreadNegative.js @@ -72,6 +72,16 @@ let overlapConflict: { id:string, a: string } = f({ a: 1 }, { a: 'mismatch' }) let overwriteId: { id: string, a: number, c: number, d: string } = f({ a: 1, id: true }, { c: 1, d: 'no' }) + +// excess property checks +type A = { a: string, b: string }; +type Extra = { a: string, b: string, extra: string }; +const extra1: A = { a: "a", b: "b", extra: "extra" }; +const extra2 = { a: "a", b: "b", extra: "extra" }; +const a1: A = { ...extra1 }; // error spans should be here +const a2: A = { ...extra2 }; // not on the symbol declarations above +const extra3: Extra = { a: "a", b: "b", extra: "extra" }; +const a3: A = { ...extra3 }; // same here //// [objectSpreadNegative.js] @@ -152,3 +162,9 @@ var exclusive = f({ a: 1, b: 'yes' }, { c: 'no', d: false }); var overlap = f({ a: 1 }, { a: 2, b: 'extra' }); var overlapConflict = f({ a: 1 }, { a: 'mismatch' }); var overwriteId = f({ a: 1, id: true }, { c: 1, d: 'no' }); +var extra1 = { a: "a", b: "b", extra: "extra" }; +var extra2 = { a: "a", b: "b", extra: "extra" }; +var a1 = __assign({}, extra1); // error spans should be here +var a2 = __assign({}, extra2); // not on the symbol declarations above +var extra3 = { a: "a", b: "b", extra: "extra" }; +var a3 = __assign({}, extra3); // same here diff --git a/tests/cases/conformance/types/spread/objectSpreadNegative.ts b/tests/cases/conformance/types/spread/objectSpreadNegative.ts index c3b42b31aa9..fced7706c96 100644 --- a/tests/cases/conformance/types/spread/objectSpreadNegative.ts +++ b/tests/cases/conformance/types/spread/objectSpreadNegative.ts @@ -72,3 +72,13 @@ let overlapConflict: { id:string, a: string } = f({ a: 1 }, { a: 'mismatch' }) let overwriteId: { id: string, a: number, c: number, d: string } = f({ a: 1, id: true }, { c: 1, d: 'no' }) + +// excess property checks +type A = { a: string, b: string }; +type Extra = { a: string, b: string, extra: string }; +const extra1: A = { a: "a", b: "b", extra: "extra" }; +const extra2 = { a: "a", b: "b", extra: "extra" }; +const a1: A = { ...extra1 }; // error spans should be here +const a2: A = { ...extra2 }; // not on the symbol declarations above +const extra3: Extra = { a: "a", b: "b", extra: "extra" }; +const a3: A = { ...extra3 }; // same here