mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Add test case related to invalid object spreads (#58105)
This commit is contained in:
parent
10b5059a95
commit
13e64740c9
15
tests/baselines/reference/spreadNonObject1.errors.txt
Normal file
15
tests/baselines/reference/spreadNonObject1.errors.txt
Normal file
@ -0,0 +1,15 @@
|
||||
spreadNonObject1.ts(6,17): error TS2698: Spread types may only be created from object types.
|
||||
|
||||
|
||||
==== spreadNonObject1.ts (1 errors) ====
|
||||
// https://github.com/microsoft/TypeScript/issues/45493
|
||||
|
||||
type S = `${number}`;
|
||||
const b = {
|
||||
c: (["4"] as S[]).map(function (s) {
|
||||
const a = { ...s, y: 6 };
|
||||
~~~~
|
||||
!!! error TS2698: Spread types may only be created from object types.
|
||||
}),
|
||||
};
|
||||
|
||||
26
tests/baselines/reference/spreadNonObject1.symbols
Normal file
26
tests/baselines/reference/spreadNonObject1.symbols
Normal file
@ -0,0 +1,26 @@
|
||||
//// [tests/cases/conformance/types/spread/spreadNonObject1.ts] ////
|
||||
|
||||
=== spreadNonObject1.ts ===
|
||||
// https://github.com/microsoft/TypeScript/issues/45493
|
||||
|
||||
type S = `${number}`;
|
||||
>S : Symbol(S, Decl(spreadNonObject1.ts, 0, 0))
|
||||
|
||||
const b = {
|
||||
>b : Symbol(b, Decl(spreadNonObject1.ts, 3, 5))
|
||||
|
||||
c: (["4"] as S[]).map(function (s) {
|
||||
>c : Symbol(c, Decl(spreadNonObject1.ts, 3, 11))
|
||||
>(["4"] as S[]).map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
|
||||
>S : Symbol(S, Decl(spreadNonObject1.ts, 0, 0))
|
||||
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
|
||||
>s : Symbol(s, Decl(spreadNonObject1.ts, 4, 34))
|
||||
|
||||
const a = { ...s, y: 6 };
|
||||
>a : Symbol(a, Decl(spreadNonObject1.ts, 5, 9))
|
||||
>s : Symbol(s, Decl(spreadNonObject1.ts, 4, 34))
|
||||
>y : Symbol(y, Decl(spreadNonObject1.ts, 5, 21))
|
||||
|
||||
}),
|
||||
};
|
||||
|
||||
52
tests/baselines/reference/spreadNonObject1.types
Normal file
52
tests/baselines/reference/spreadNonObject1.types
Normal file
@ -0,0 +1,52 @@
|
||||
//// [tests/cases/conformance/types/spread/spreadNonObject1.ts] ////
|
||||
|
||||
=== spreadNonObject1.ts ===
|
||||
// https://github.com/microsoft/TypeScript/issues/45493
|
||||
|
||||
type S = `${number}`;
|
||||
>S : `${number}`
|
||||
> : ^^^^^^^^^^^
|
||||
|
||||
const b = {
|
||||
>b : { c: void[]; }
|
||||
> : ^^^^^^^^^^^^^^
|
||||
>{ c: (["4"] as S[]).map(function (s) { const a = { ...s, y: 6 }; }),} : { c: void[]; }
|
||||
> : ^^^^^^^^^^^^^^
|
||||
|
||||
c: (["4"] as S[]).map(function (s) {
|
||||
>c : void[]
|
||||
> : ^^^^^^
|
||||
>(["4"] as S[]).map(function (s) { const a = { ...s, y: 6 }; }) : void[]
|
||||
> : ^^^^^^
|
||||
>(["4"] as S[]).map : <U>(callbackfn: (value: `${number}`, index: number, array: `${number}`[]) => U, thisArg?: any) => U[]
|
||||
> : ^^^^ ^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
|
||||
>(["4"] as S[]) : `${number}`[]
|
||||
> : ^^^^^^^^^^^^^
|
||||
>["4"] as S[] : `${number}`[]
|
||||
> : ^^^^^^^^^^^^^
|
||||
>["4"] : "4"[]
|
||||
> : ^^^^^
|
||||
>"4" : "4"
|
||||
> : ^^^
|
||||
>map : <U>(callbackfn: (value: `${number}`, index: number, array: `${number}`[]) => U, thisArg?: any) => U[]
|
||||
> : ^^^^ ^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
|
||||
>function (s) { const a = { ...s, y: 6 }; } : (s: `${number}`) => void
|
||||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^
|
||||
>s : `${number}`
|
||||
> : ^^^^^^^^^^^
|
||||
|
||||
const a = { ...s, y: 6 };
|
||||
>a : any
|
||||
> : ^^^
|
||||
>{ ...s, y: 6 } : any
|
||||
> : ^^^
|
||||
>s : `${number}`
|
||||
> : ^^^^^^^^^^^
|
||||
>y : number
|
||||
> : ^^^^^^
|
||||
>6 : 6
|
||||
> : ^
|
||||
|
||||
}),
|
||||
};
|
||||
|
||||
11
tests/cases/conformance/types/spread/spreadNonObject1.ts
Normal file
11
tests/cases/conformance/types/spread/spreadNonObject1.ts
Normal file
@ -0,0 +1,11 @@
|
||||
// @strict: true
|
||||
// @noEmit: true
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/45493
|
||||
|
||||
type S = `${number}`;
|
||||
const b = {
|
||||
c: (["4"] as S[]).map(function (s) {
|
||||
const a = { ...s, y: 6 };
|
||||
}),
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user