Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case related to invalid object spreads #58105

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/baselines/reference/spreadNonObject1.errors.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 26 additions & 0 deletions tests/baselines/reference/spreadNonObject1.symbols
Original file line number Diff line number Diff line change
@@ -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 changes: 52 additions & 0 deletions tests/baselines/reference/spreadNonObject1.types
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions tests/cases/conformance/types/spread/spreadNonObject1.ts
Original file line number Diff line number Diff line change
@@ -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 };
}),
};