-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Fixed incorrect SignatureFlags.HasRestParameter
propagation when combining signatures
#58440
Open
Andarist
wants to merge
3
commits into
microsoft:main
Choose a base branch
from
Andarist:fix/has-rest-parameter-when-combining-signatures
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
29 changes: 29 additions & 0 deletions
29
tests/baselines/reference/signatureCombiningRestParameters1.errors.txt
This file contains 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,29 @@ | ||
signatureCombiningRestParameters1.ts(17,6): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. | ||
|
||
|
||
==== signatureCombiningRestParameters1.ts (1 errors) ==== | ||
// https://github.com/microsoft/TypeScript/issues/58371 | ||
|
||
type T1 = "A" | "B"; | ||
|
||
type T2 = { | ||
C: [string]; | ||
D: [number]; | ||
}; | ||
|
||
declare const map: { | ||
[K in T1 | keyof T2]: (...args: K extends keyof T2 ? T2[K] : []) => unknown; | ||
}; | ||
|
||
declare const args: any; | ||
|
||
for (const [key, fn] of Object.entries(map)) { | ||
fn(...args); | ||
~~~~~~~ | ||
!!! error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. | ||
} | ||
|
||
const test2: ((a: number, ...args: []) => void) & | ||
((b: string) => void) & | ||
((c: boolean) => void) = (arg) => {}; | ||
|
62 changes: 62 additions & 0 deletions
62
tests/baselines/reference/signatureCombiningRestParameters1.symbols
This file contains 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,62 @@ | ||
//// [tests/cases/compiler/signatureCombiningRestParameters1.ts] //// | ||
|
||
=== signatureCombiningRestParameters1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/58371 | ||
|
||
type T1 = "A" | "B"; | ||
>T1 : Symbol(T1, Decl(signatureCombiningRestParameters1.ts, 0, 0)) | ||
|
||
type T2 = { | ||
>T2 : Symbol(T2, Decl(signatureCombiningRestParameters1.ts, 2, 20)) | ||
|
||
C: [string]; | ||
>C : Symbol(C, Decl(signatureCombiningRestParameters1.ts, 4, 11)) | ||
|
||
D: [number]; | ||
>D : Symbol(D, Decl(signatureCombiningRestParameters1.ts, 5, 14)) | ||
|
||
}; | ||
|
||
declare const map: { | ||
>map : Symbol(map, Decl(signatureCombiningRestParameters1.ts, 9, 13)) | ||
|
||
[K in T1 | keyof T2]: (...args: K extends keyof T2 ? T2[K] : []) => unknown; | ||
>K : Symbol(K, Decl(signatureCombiningRestParameters1.ts, 10, 3)) | ||
>T1 : Symbol(T1, Decl(signatureCombiningRestParameters1.ts, 0, 0)) | ||
>T2 : Symbol(T2, Decl(signatureCombiningRestParameters1.ts, 2, 20)) | ||
>args : Symbol(args, Decl(signatureCombiningRestParameters1.ts, 10, 25)) | ||
>K : Symbol(K, Decl(signatureCombiningRestParameters1.ts, 10, 3)) | ||
>T2 : Symbol(T2, Decl(signatureCombiningRestParameters1.ts, 2, 20)) | ||
>T2 : Symbol(T2, Decl(signatureCombiningRestParameters1.ts, 2, 20)) | ||
>K : Symbol(K, Decl(signatureCombiningRestParameters1.ts, 10, 3)) | ||
|
||
}; | ||
|
||
declare const args: any; | ||
>args : Symbol(args, Decl(signatureCombiningRestParameters1.ts, 13, 13)) | ||
|
||
for (const [key, fn] of Object.entries(map)) { | ||
>key : Symbol(key, Decl(signatureCombiningRestParameters1.ts, 15, 12)) | ||
>fn : Symbol(fn, Decl(signatureCombiningRestParameters1.ts, 15, 16)) | ||
>Object.entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) | ||
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) | ||
>map : Symbol(map, Decl(signatureCombiningRestParameters1.ts, 9, 13)) | ||
|
||
fn(...args); | ||
>fn : Symbol(fn, Decl(signatureCombiningRestParameters1.ts, 15, 16)) | ||
>args : Symbol(args, Decl(signatureCombiningRestParameters1.ts, 13, 13)) | ||
} | ||
|
||
const test2: ((a: number, ...args: []) => void) & | ||
>test2 : Symbol(test2, Decl(signatureCombiningRestParameters1.ts, 19, 5)) | ||
>a : Symbol(a, Decl(signatureCombiningRestParameters1.ts, 19, 15)) | ||
>args : Symbol(args, Decl(signatureCombiningRestParameters1.ts, 19, 25)) | ||
|
||
((b: string) => void) & | ||
>b : Symbol(b, Decl(signatureCombiningRestParameters1.ts, 20, 4)) | ||
|
||
((c: boolean) => void) = (arg) => {}; | ||
>c : Symbol(c, Decl(signatureCombiningRestParameters1.ts, 21, 4)) | ||
>arg : Symbol(arg, Decl(signatureCombiningRestParameters1.ts, 21, 28)) | ||
|
84 changes: 84 additions & 0 deletions
84
tests/baselines/reference/signatureCombiningRestParameters1.types
This file contains 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,84 @@ | ||
//// [tests/cases/compiler/signatureCombiningRestParameters1.ts] //// | ||
|
||
=== signatureCombiningRestParameters1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/58371 | ||
|
||
type T1 = "A" | "B"; | ||
>T1 : T1 | ||
> : ^^ | ||
|
||
type T2 = { | ||
>T2 : T2 | ||
> : ^^ | ||
|
||
C: [string]; | ||
>C : [string] | ||
> : ^^^^^^^^ | ||
|
||
D: [number]; | ||
>D : [number] | ||
> : ^^^^^^^^ | ||
|
||
}; | ||
|
||
declare const map: { | ||
>map : { A: () => unknown; B: () => unknown; C: (args_0: string) => unknown; D: (args_0: number) => unknown; } | ||
> : ^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ | ||
|
||
[K in T1 | keyof T2]: (...args: K extends keyof T2 ? T2[K] : []) => unknown; | ||
>args : K extends keyof T2 ? T2[K] : [] | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
}; | ||
|
||
declare const args: any; | ||
>args : any | ||
> : ^^^ | ||
|
||
for (const [key, fn] of Object.entries(map)) { | ||
>key : string | ||
> : ^^^^^^ | ||
>fn : (() => unknown) | (() => unknown) | ((args_0: string) => unknown) | ((args_0: number) => unknown) | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>Object.entries(map) : [string, (() => unknown) | (() => unknown) | ((args_0: string) => unknown) | ((args_0: number) => unknown)][] | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>Object.entries : { <T>(o: { [s: string]: T; } | ArrayLike<T>): [string, T][]; (o: {}): [string, any][]; } | ||
> : ^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ | ||
>Object : ObjectConstructor | ||
> : ^^^^^^^^^^^^^^^^^ | ||
>entries : { <T>(o: { [s: string]: T; } | ArrayLike<T>): [string, T][]; (o: {}): [string, any][]; } | ||
> : ^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ | ||
>map : { A: () => unknown; B: () => unknown; C: (args_0: string) => unknown; D: (args_0: number) => unknown; } | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
fn(...args); | ||
>fn(...args) : unknown | ||
> : ^^^^^^^ | ||
>fn : (() => unknown) | (() => unknown) | ((args_0: string) => unknown) | ((args_0: number) => unknown) | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>...args : any | ||
> : ^^^ | ||
>args : any | ||
> : ^^^ | ||
} | ||
|
||
const test2: ((a: number, ...args: []) => void) & | ||
>test2 : ((a: number) => void) & ((b: string) => void) & ((c: boolean) => void) | ||
> : ^^ ^^ ^^^^^ ^^^^^^ ^^ ^^^^^ ^^^^^^ ^^ ^^^^^ ^ | ||
>a : number | ||
> : ^^^^^^ | ||
>args : [] | ||
> : ^^ | ||
|
||
((b: string) => void) & | ||
>b : string | ||
> : ^^^^^^ | ||
|
||
((c: boolean) => void) = (arg) => {}; | ||
>c : boolean | ||
> : ^^^^^^^ | ||
>(arg) => {} : (arg: string | number | boolean) => void | ||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>arg : string | number | boolean | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
35 changes: 35 additions & 0 deletions
35
tests/baselines/reference/signatureCombiningRestParameters2.symbols
This file contains 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,35 @@ | ||
//// [tests/cases/compiler/signatureCombiningRestParameters2.ts] //// | ||
|
||
=== signatureCombiningRestParameters2.ts === | ||
interface Console { | ||
>Console : Symbol(Console, Decl(lib.dom.d.ts, --, --), Decl(signatureCombiningRestParameters2.ts, 0, 0)) | ||
|
||
log(message?: any, ...optionalParams: any[]): void; | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --), Decl(signatureCombiningRestParameters2.ts, 0, 19)) | ||
>message : Symbol(message, Decl(signatureCombiningRestParameters2.ts, 1, 6)) | ||
>optionalParams : Symbol(optionalParams, Decl(signatureCombiningRestParameters2.ts, 1, 20)) | ||
} | ||
|
||
let logs: string[] = []; | ||
>logs : Symbol(logs, Decl(signatureCombiningRestParameters2.ts, 4, 3)) | ||
|
||
let originalLog: typeof console.log; | ||
>originalLog : Symbol(originalLog, Decl(signatureCombiningRestParameters2.ts, 5, 3)) | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --), Decl(signatureCombiningRestParameters2.ts, 0, 19)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --), Decl(signatureCombiningRestParameters2.ts, 0, 19)) | ||
|
||
console.log = (...args) => { | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --), Decl(signatureCombiningRestParameters2.ts, 0, 19)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --), Decl(signatureCombiningRestParameters2.ts, 0, 19)) | ||
>args : Symbol(args, Decl(signatureCombiningRestParameters2.ts, 6, 15)) | ||
|
||
logs.push(...args); | ||
>logs.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) | ||
>logs : Symbol(logs, Decl(signatureCombiningRestParameters2.ts, 4, 3)) | ||
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) | ||
>args : Symbol(args, Decl(signatureCombiningRestParameters2.ts, 6, 15)) | ||
|
||
}; | ||
|
57 changes: 57 additions & 0 deletions
57
tests/baselines/reference/signatureCombiningRestParameters2.types
This file contains 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 @@ | ||
//// [tests/cases/compiler/signatureCombiningRestParameters2.ts] //// | ||
|
||
=== signatureCombiningRestParameters2.ts === | ||
interface Console { | ||
log(message?: any, ...optionalParams: any[]): void; | ||
>log : { (...data: any[]): void; (message?: any, ...optionalParams: any[]): void; } | ||
> : ^^^^^^ ^^ ^^^^^^^^^^ ^^^ ^^^^^ ^^ ^^^ ^^^ | ||
>message : any | ||
>optionalParams : any[] | ||
> : ^^^^^ | ||
} | ||
|
||
let logs: string[] = []; | ||
>logs : string[] | ||
> : ^^^^^^^^ | ||
>[] : never[] | ||
> : ^^^^^^^ | ||
|
||
let originalLog: typeof console.log; | ||
>originalLog : { (...data: any[]): void; (message?: any, ...optionalParams: any[]): void; } | ||
> : ^^^^^^ ^^ ^^^^^^^^^^ ^^^ ^^^^^ ^^ ^^^^^^^^^^ | ||
>console.log : { (...data: any[]): void; (message?: any, ...optionalParams: any[]): void; } | ||
> : ^^^^^^ ^^ ^^^^^^^^^^ ^^^ ^^^^^ ^^ ^^^^^^^^^^ | ||
>console : Console | ||
> : ^^^^^^^ | ||
>log : { (...data: any[]): void; (message?: any, ...optionalParams: any[]): void; } | ||
> : ^^^^^^ ^^ ^^^^^^^^^^ ^^^ ^^^^^ ^^ ^^^^^^^^^^ | ||
|
||
console.log = (...args) => { | ||
>console.log = (...args) => { logs.push(...args);} : (args_0?: any, ...args_1: any[]) => void | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>console.log : { (...data: any[]): void; (message?: any, ...optionalParams: any[]): void; } | ||
> : ^^^^^^ ^^ ^^^^^^^^^^ ^^^ ^^^^^ ^^ ^^^^^^^^^^ | ||
>console : Console | ||
> : ^^^^^^^ | ||
>log : { (...data: any[]): void; (message?: any, ...optionalParams: any[]): void; } | ||
> : ^^^^^^ ^^ ^^^^^^^^^^ ^^^ ^^^^^ ^^ ^^^^^^^^^^ | ||
>(...args) => { logs.push(...args);} : (args_0?: any, ...args_1: any[]) => void | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>args : [any?, ...any[]] | ||
> : ^^^^^^^^^^^^^^^^ | ||
|
||
logs.push(...args); | ||
>logs.push(...args) : number | ||
> : ^^^^^^ | ||
>logs.push : (...items: string[]) => number | ||
> : ^^^^ ^^^^^^^^^^^^^^^^^^^^^ | ||
>logs : string[] | ||
> : ^^^^^^^^ | ||
>push : (...items: string[]) => number | ||
> : ^^^^ ^^^^^^^^^^^^^^^^^^^^^ | ||
>...args : any | ||
>args : [any?, ...any[]] | ||
> : ^^^^^^^^^^^^^^^^ | ||
|
||
}; | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding
CheckFlags.RestParameter
here is based on the similar change from #55625