Skip to content

Commit 13e6474

Browse files
authored
Add test case related to invalid object spreads (microsoft#58105)
1 parent 10b5059 commit 13e6474

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
spreadNonObject1.ts(6,17): error TS2698: Spread types may only be created from object types.
2+
3+
4+
==== spreadNonObject1.ts (1 errors) ====
5+
// https://github.com/microsoft/TypeScript/issues/45493
6+
7+
type S = `${number}`;
8+
const b = {
9+
c: (["4"] as S[]).map(function (s) {
10+
const a = { ...s, y: 6 };
11+
~~~~
12+
!!! error TS2698: Spread types may only be created from object types.
13+
}),
14+
};
15+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [tests/cases/conformance/types/spread/spreadNonObject1.ts] ////
2+
3+
=== spreadNonObject1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/45493
5+
6+
type S = `${number}`;
7+
>S : Symbol(S, Decl(spreadNonObject1.ts, 0, 0))
8+
9+
const b = {
10+
>b : Symbol(b, Decl(spreadNonObject1.ts, 3, 5))
11+
12+
c: (["4"] as S[]).map(function (s) {
13+
>c : Symbol(c, Decl(spreadNonObject1.ts, 3, 11))
14+
>(["4"] as S[]).map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
15+
>S : Symbol(S, Decl(spreadNonObject1.ts, 0, 0))
16+
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
17+
>s : Symbol(s, Decl(spreadNonObject1.ts, 4, 34))
18+
19+
const a = { ...s, y: 6 };
20+
>a : Symbol(a, Decl(spreadNonObject1.ts, 5, 9))
21+
>s : Symbol(s, Decl(spreadNonObject1.ts, 4, 34))
22+
>y : Symbol(y, Decl(spreadNonObject1.ts, 5, 21))
23+
24+
}),
25+
};
26+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//// [tests/cases/conformance/types/spread/spreadNonObject1.ts] ////
2+
3+
=== spreadNonObject1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/45493
5+
6+
type S = `${number}`;
7+
>S : `${number}`
8+
> : ^^^^^^^^^^^
9+
10+
const b = {
11+
>b : { c: void[]; }
12+
> : ^^^^^^^^^^^^^^
13+
>{ c: (["4"] as S[]).map(function (s) { const a = { ...s, y: 6 }; }),} : { c: void[]; }
14+
> : ^^^^^^^^^^^^^^
15+
16+
c: (["4"] as S[]).map(function (s) {
17+
>c : void[]
18+
> : ^^^^^^
19+
>(["4"] as S[]).map(function (s) { const a = { ...s, y: 6 }; }) : void[]
20+
> : ^^^^^^
21+
>(["4"] as S[]).map : <U>(callbackfn: (value: `${number}`, index: number, array: `${number}`[]) => U, thisArg?: any) => U[]
22+
> : ^^^^ ^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
23+
>(["4"] as S[]) : `${number}`[]
24+
> : ^^^^^^^^^^^^^
25+
>["4"] as S[] : `${number}`[]
26+
> : ^^^^^^^^^^^^^
27+
>["4"] : "4"[]
28+
> : ^^^^^
29+
>"4" : "4"
30+
> : ^^^
31+
>map : <U>(callbackfn: (value: `${number}`, index: number, array: `${number}`[]) => U, thisArg?: any) => U[]
32+
> : ^^^^ ^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
33+
>function (s) { const a = { ...s, y: 6 }; } : (s: `${number}`) => void
34+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^
35+
>s : `${number}`
36+
> : ^^^^^^^^^^^
37+
38+
const a = { ...s, y: 6 };
39+
>a : any
40+
> : ^^^
41+
>{ ...s, y: 6 } : any
42+
> : ^^^
43+
>s : `${number}`
44+
> : ^^^^^^^^^^^
45+
>y : number
46+
> : ^^^^^^
47+
>6 : 6
48+
> : ^
49+
50+
}),
51+
};
52+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// https://github.com/microsoft/TypeScript/issues/45493
5+
6+
type S = `${number}`;
7+
const b = {
8+
c: (["4"] as S[]).map(function (s) {
9+
const a = { ...s, y: 6 };
10+
}),
11+
};

0 commit comments

Comments
 (0)