-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Restrict spreading for Instantiable Type with non object constraint #31185
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| tests/cases/conformance/types/spread/spreadTypeVariable.ts(2,12): error TS2698: Spread types may only be created from object types. | ||
| tests/cases/conformance/types/spread/spreadTypeVariable.ts(10,12): error TS2698: Spread types may only be created from object types. | ||
| tests/cases/conformance/types/spread/spreadTypeVariable.ts(14,12): error TS2698: Spread types may only be created from object types. | ||
|
|
||
|
|
||
| ==== tests/cases/conformance/types/spread/spreadTypeVariable.ts (3 errors) ==== | ||
| function f1<T extends number>(arg: T) { | ||
| return { ...arg }; | ||
| ~~~~~~ | ||
| !!! error TS2698: Spread types may only be created from object types. | ||
| } | ||
|
|
||
| function f2<T extends string[]>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
| function f3<T extends number | string[]>(arg: T) { | ||
| return { ...arg } | ||
| ~~~~~~ | ||
| !!! error TS2698: Spread types may only be created from object types. | ||
| } | ||
|
|
||
| function f4<T extends number | { [key: string]: any }>(arg: T) { | ||
| return { ...arg } | ||
| ~~~~~~ | ||
| !!! error TS2698: Spread types may only be created from object types. | ||
| } | ||
|
|
||
| function f5<T extends string[] | { [key: string]: any }>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
| function f6<T>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //// [spreadTypeVariable.ts] | ||
| function f1<T extends number>(arg: T) { | ||
| return { ...arg }; | ||
| } | ||
|
|
||
| function f2<T extends string[]>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
| function f3<T extends number | string[]>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
| function f4<T extends number | { [key: string]: any }>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
| function f5<T extends string[] | { [key: string]: any }>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
| function f6<T>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| //// [spreadTypeVariable.js] | ||
| var __assign = (this && this.__assign) || function () { | ||
| __assign = Object.assign || function(t) { | ||
| for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
| s = arguments[i]; | ||
| for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
| t[p] = s[p]; | ||
| } | ||
| return t; | ||
| }; | ||
| return __assign.apply(this, arguments); | ||
| }; | ||
| function f1(arg) { | ||
| return __assign({}, arg); | ||
| } | ||
| function f2(arg) { | ||
| return __assign({}, arg); | ||
| } | ||
| function f3(arg) { | ||
| return __assign({}, arg); | ||
| } | ||
| function f4(arg) { | ||
| return __assign({}, arg); | ||
| } | ||
| function f5(arg) { | ||
| return __assign({}, arg); | ||
| } | ||
| function f6(arg) { | ||
| return __assign({}, arg); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| === tests/cases/conformance/types/spread/spreadTypeVariable.ts === | ||
| function f1<T extends number>(arg: T) { | ||
| >f1 : Symbol(f1, Decl(spreadTypeVariable.ts, 0, 0)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 0, 12)) | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 0, 30)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 0, 12)) | ||
|
|
||
| return { ...arg }; | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 0, 30)) | ||
| } | ||
|
|
||
| function f2<T extends string[]>(arg: T) { | ||
| >f2 : Symbol(f2, Decl(spreadTypeVariable.ts, 2, 1)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 4, 12)) | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 4, 32)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 4, 12)) | ||
|
|
||
| return { ...arg } | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 4, 32)) | ||
| } | ||
|
|
||
| function f3<T extends number | string[]>(arg: T) { | ||
| >f3 : Symbol(f3, Decl(spreadTypeVariable.ts, 6, 1)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 8, 12)) | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 8, 41)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 8, 12)) | ||
|
|
||
| return { ...arg } | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 8, 41)) | ||
| } | ||
|
|
||
| function f4<T extends number | { [key: string]: any }>(arg: T) { | ||
| >f4 : Symbol(f4, Decl(spreadTypeVariable.ts, 10, 1)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 12, 12)) | ||
| >key : Symbol(key, Decl(spreadTypeVariable.ts, 12, 34)) | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 12, 55)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 12, 12)) | ||
|
|
||
| return { ...arg } | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 12, 55)) | ||
| } | ||
|
|
||
| function f5<T extends string[] | { [key: string]: any }>(arg: T) { | ||
| >f5 : Symbol(f5, Decl(spreadTypeVariable.ts, 14, 1)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 16, 12)) | ||
| >key : Symbol(key, Decl(spreadTypeVariable.ts, 16, 36)) | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 16, 57)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 16, 12)) | ||
|
|
||
| return { ...arg } | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 16, 57)) | ||
| } | ||
|
|
||
| function f6<T>(arg: T) { | ||
| >f6 : Symbol(f6, Decl(spreadTypeVariable.ts, 18, 1)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 20, 12)) | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 20, 15)) | ||
| >T : Symbol(T, Decl(spreadTypeVariable.ts, 20, 12)) | ||
|
|
||
| return { ...arg } | ||
| >arg : Symbol(arg, Decl(spreadTypeVariable.ts, 20, 15)) | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| === tests/cases/conformance/types/spread/spreadTypeVariable.ts === | ||
| function f1<T extends number>(arg: T) { | ||
| >f1 : <T extends number>(arg: T) => any | ||
| >arg : T | ||
|
|
||
| return { ...arg }; | ||
| >{ ...arg } : any | ||
| >arg : T | ||
| } | ||
|
|
||
| function f2<T extends string[]>(arg: T) { | ||
| >f2 : <T extends string[]>(arg: T) => T | ||
| >arg : T | ||
|
|
||
| return { ...arg } | ||
| >{ ...arg } : T | ||
| >arg : T | ||
| } | ||
|
|
||
| function f3<T extends number | string[]>(arg: T) { | ||
| >f3 : <T extends number | string[]>(arg: T) => any | ||
| >arg : T | ||
|
|
||
| return { ...arg } | ||
| >{ ...arg } : any | ||
| >arg : T | ||
| } | ||
|
|
||
| function f4<T extends number | { [key: string]: any }>(arg: T) { | ||
| >f4 : <T extends number | { [key: string]: any; }>(arg: T) => any | ||
| >key : string | ||
| >arg : T | ||
|
|
||
| return { ...arg } | ||
| >{ ...arg } : any | ||
| >arg : T | ||
| } | ||
|
|
||
| function f5<T extends string[] | { [key: string]: any }>(arg: T) { | ||
| >f5 : <T extends string[] | { [key: string]: any; }>(arg: T) => T | ||
| >key : string | ||
| >arg : T | ||
|
|
||
| return { ...arg } | ||
| >{ ...arg } : T | ||
| >arg : T | ||
| } | ||
|
|
||
| function f6<T>(arg: T) { | ||
| >f6 : <T>(arg: T) => T | ||
| >arg : T | ||
|
|
||
| return { ...arg } | ||
| >{ ...arg } : T | ||
| >arg : T | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/cases/conformance/types/spread/spreadTypeVariable.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| function f1<T extends number>(arg: T) { | ||
| return { ...arg }; | ||
| } | ||
|
|
||
| function f2<T extends string[]>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
| function f3<T extends number | string[]>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
| function f4<T extends number | { [key: string]: any }>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
| function f5<T extends string[] | { [key: string]: any }>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
||
| function f6<T>(arg: T) { | ||
| return { ...arg } | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.