Skip to content

Commit 0913ef6

Browse files
committed
Test:error span for spread prop in excess prop check
1 parent b394182 commit 0913ef6

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

tests/baselines/reference/objectSpreadNegative.errors.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ 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'.
21+
Object literal may only specify known properties, and 'extra' does not exist in type 'A'.
22+
tests/cases/conformance/types/spread/objectSpreadNegative.ts(81,7): error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'.
23+
Object literal may only specify known properties, and 'extra' does not exist in type 'A'.
24+
tests/cases/conformance/types/spread/objectSpreadNegative.ts(83,7): error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'.
25+
Object literal may only specify known properties, and 'extra' does not exist in type 'A'.
2026

2127

22-
==== tests/cases/conformance/types/spread/objectSpreadNegative.ts (16 errors) ====
28+
==== tests/cases/conformance/types/spread/objectSpreadNegative.ts (19 errors) ====
2329
let o = { a: 1, b: 'no' }
2430

2531
/// private propagates
@@ -128,4 +134,23 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(64,14): error TS269
128134
f({ a: 1 }, { a: 'mismatch' })
129135
let overwriteId: { id: string, a: number, c: number, d: string } =
130136
f({ a: 1, id: true }, { c: 1, d: 'no' })
137+
138+
// excess property checks
139+
type A = { a: string, b: string };
140+
type Extra = { a: string, b: string, extra: string };
141+
const extra1: A = { a: "a", b: "b", extra: "extra" };
142+
~~~~~~
143+
!!! error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'.
144+
!!! error TS2322: Object literal may only specify known properties, and 'extra' does not exist in type 'A'.
145+
const extra2 = { a: "a", b: "b", extra: "extra" };
146+
const a1: A = { ...extra1 }; // error spans should be here
147+
const a2: A = { ...extra2 }; // not on the symbol declarations above
148+
~~
149+
!!! error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'.
150+
!!! error TS2322: Object literal may only specify known properties, and 'extra' does not exist in type 'A'.
151+
const extra3: Extra = { a: "a", b: "b", extra: "extra" };
152+
const a3: A = { ...extra3 }; // same here
153+
~~
154+
!!! error TS2322: Type '{ a: string; b: string; extra: string; }' is not assignable to type 'A'.
155+
!!! error TS2322: Object literal may only specify known properties, and 'extra' does not exist in type 'A'.
131156

tests/baselines/reference/objectSpreadNegative.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ let overlapConflict: { id:string, a: string } =
7272
f({ a: 1 }, { a: 'mismatch' })
7373
let overwriteId: { id: string, a: number, c: number, d: string } =
7474
f({ a: 1, id: true }, { c: 1, d: 'no' })
75+
76+
// excess property checks
77+
type A = { a: string, b: string };
78+
type Extra = { a: string, b: string, extra: string };
79+
const extra1: A = { a: "a", b: "b", extra: "extra" };
80+
const extra2 = { a: "a", b: "b", extra: "extra" };
81+
const a1: A = { ...extra1 }; // error spans should be here
82+
const a2: A = { ...extra2 }; // not on the symbol declarations above
83+
const extra3: Extra = { a: "a", b: "b", extra: "extra" };
84+
const a3: A = { ...extra3 }; // same here
7585

7686

7787
//// [objectSpreadNegative.js]
@@ -152,3 +162,9 @@ var exclusive = f({ a: 1, b: 'yes' }, { c: 'no', d: false });
152162
var overlap = f({ a: 1 }, { a: 2, b: 'extra' });
153163
var overlapConflict = f({ a: 1 }, { a: 'mismatch' });
154164
var overwriteId = f({ a: 1, id: true }, { c: 1, d: 'no' });
165+
var extra1 = { a: "a", b: "b", extra: "extra" };
166+
var extra2 = { a: "a", b: "b", extra: "extra" };
167+
var a1 = __assign({}, extra1); // error spans should be here
168+
var a2 = __assign({}, extra2); // not on the symbol declarations above
169+
var extra3 = { a: "a", b: "b", extra: "extra" };
170+
var a3 = __assign({}, extra3); // same here

tests/cases/conformance/types/spread/objectSpreadNegative.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,13 @@ let overlapConflict: { id:string, a: string } =
7272
f({ a: 1 }, { a: 'mismatch' })
7373
let overwriteId: { id: string, a: number, c: number, d: string } =
7474
f({ a: 1, id: true }, { c: 1, d: 'no' })
75+
76+
// excess property checks
77+
type A = { a: string, b: string };
78+
type Extra = { a: string, b: string, extra: string };
79+
const extra1: A = { a: "a", b: "b", extra: "extra" };
80+
const extra2 = { a: "a", b: "b", extra: "extra" };
81+
const a1: A = { ...extra1 }; // error spans should be here
82+
const a2: A = { ...extra2 }; // not on the symbol declarations above
83+
const extra3: Extra = { a: "a", b: "b", extra: "extra" };
84+
const a3: A = { ...extra3 }; // same here

0 commit comments

Comments
 (0)