-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Allow identical type parameter lists to merge in union signatures #31023
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
weswigham
merged 7 commits into
microsoft:master
from
weswigham:better-signature-identity-checks
Dec 16, 2020
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6df05fa
Have signature identity checks look at the base constraint of type pa…
weswigham d36dfcb
Update text in fourslash test
weswigham 0580cca
Add whitespace to fix lint, remove duplicate impl
weswigham 01dea4b
Consolidate names
weswigham 40d4f30
Merge branch 'master' into better-signature-identity-checks
weswigham e14c58e
Remove comparisons of type parameter defaults, add more test cases
weswigham 3037443
Merge branch 'master' into better-signature-identity-checks
weswigham 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| tests/cases/compiler/unionOfClassCalls.ts(28,5): error TS2349: This expression is not callable. | ||
| Each member of the union type '{ (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; <U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; }' has signatures, but none of those signatures are compatible with each other. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/unionOfClassCalls.ts (1 errors) ==== | ||
| // from https://github.com/microsoft/TypeScript/issues/30717 | ||
| declare class Test<T> { | ||
| obj: T; | ||
| get<K extends keyof T>(k: K): T[K]; | ||
| } | ||
|
|
||
| interface A { t: "A" } | ||
| interface B { t: "B" } | ||
|
|
||
| declare const tmp: Test<A> | Test<B>; | ||
|
|
||
| switch (tmp.get('t')) { | ||
| case 'A': break; | ||
| case 'B': break; | ||
| } | ||
|
|
||
| // from https://github.com/microsoft/TypeScript/issues/36390 | ||
|
|
||
| const arr: number[] | string[] = []; // Works with Array<number | string> | ||
| const arr1: number[] = []; | ||
| const arr2: string[] = []; | ||
|
|
||
| arr.map((a: number | string, index: number) => { | ||
| return index | ||
| }) | ||
|
|
||
| // This case still doesn't work because `reduce` has multiple overloads :( | ||
| arr.reduce((acc: Array<string>, a: number | string, index: number) => { | ||
| ~~~~~~ | ||
| !!! error TS2349: This expression is not callable. | ||
| !!! error TS2349: Each member of the union type '{ (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } | { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; <U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; }' has signatures, but none of those signatures are compatible with each other. | ||
| return [] | ||
| }, []) | ||
|
|
||
| arr.forEach((a: number | string, index: number) => { | ||
| return index | ||
| }) | ||
|
|
||
| arr1.map((a: number, index: number) => { | ||
| return index | ||
| }) | ||
|
|
||
| arr1.reduce((acc: number[], a: number, index: number) => { | ||
| return [a] | ||
| }, []) | ||
|
|
||
| arr1.forEach((a: number, index: number) => { | ||
| return index | ||
| }) | ||
| arr2.map((a: string, index: number) => { | ||
| return index | ||
| }) | ||
|
|
||
| arr2.reduce((acc: string[], a: string, index: number) => { | ||
| return [] | ||
| }, []) | ||
|
|
||
| arr2.forEach((a: string, index: number) => { | ||
| return index | ||
| }) | ||
|
|
||
| // from https://github.com/microsoft/TypeScript/issues/36307 | ||
|
|
||
| declare class Foo { | ||
| doThing(): Promise<this> | ||
| } | ||
|
|
||
| declare class Bar extends Foo { | ||
| bar: number; | ||
| } | ||
| declare class Baz extends Foo { | ||
| baz: number; | ||
| } | ||
|
|
||
| declare var a: Bar | Baz; | ||
| // note, you must annotate `result` for now | ||
| a.doThing().then((result: Bar | Baz) => { | ||
| // whatever | ||
| }); | ||
|
|
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,121 @@ | ||
| //// [unionOfClassCalls.ts] | ||
| // from https://github.com/microsoft/TypeScript/issues/30717 | ||
| declare class Test<T> { | ||
| obj: T; | ||
| get<K extends keyof T>(k: K): T[K]; | ||
| } | ||
|
|
||
| interface A { t: "A" } | ||
| interface B { t: "B" } | ||
|
|
||
| declare const tmp: Test<A> | Test<B>; | ||
|
|
||
| switch (tmp.get('t')) { | ||
| case 'A': break; | ||
| case 'B': break; | ||
| } | ||
|
|
||
| // from https://github.com/microsoft/TypeScript/issues/36390 | ||
|
|
||
| const arr: number[] | string[] = []; // Works with Array<number | string> | ||
| const arr1: number[] = []; | ||
| const arr2: string[] = []; | ||
|
|
||
| arr.map((a: number | string, index: number) => { | ||
| return index | ||
| }) | ||
|
|
||
| // This case still doesn't work because `reduce` has multiple overloads :( | ||
| arr.reduce((acc: Array<string>, a: number | string, index: number) => { | ||
| return [] | ||
| }, []) | ||
|
|
||
| arr.forEach((a: number | string, index: number) => { | ||
| return index | ||
| }) | ||
|
|
||
| arr1.map((a: number, index: number) => { | ||
| return index | ||
| }) | ||
|
|
||
| arr1.reduce((acc: number[], a: number, index: number) => { | ||
| return [a] | ||
| }, []) | ||
|
|
||
| arr1.forEach((a: number, index: number) => { | ||
| return index | ||
| }) | ||
| arr2.map((a: string, index: number) => { | ||
| return index | ||
| }) | ||
|
|
||
| arr2.reduce((acc: string[], a: string, index: number) => { | ||
| return [] | ||
| }, []) | ||
|
|
||
| arr2.forEach((a: string, index: number) => { | ||
| return index | ||
| }) | ||
|
|
||
| // from https://github.com/microsoft/TypeScript/issues/36307 | ||
|
|
||
| declare class Foo { | ||
| doThing(): Promise<this> | ||
| } | ||
|
|
||
| declare class Bar extends Foo { | ||
| bar: number; | ||
| } | ||
| declare class Baz extends Foo { | ||
| baz: number; | ||
| } | ||
|
|
||
| declare var a: Bar | Baz; | ||
| // note, you must annotate `result` for now | ||
| a.doThing().then((result: Bar | Baz) => { | ||
| // whatever | ||
| }); | ||
|
|
||
|
|
||
| //// [unionOfClassCalls.js] | ||
| "use strict"; | ||
| switch (tmp.get('t')) { | ||
| case 'A': break; | ||
| case 'B': break; | ||
| } | ||
| // from https://github.com/microsoft/TypeScript/issues/36390 | ||
| var arr = []; // Works with Array<number | string> | ||
| var arr1 = []; | ||
| var arr2 = []; | ||
| arr.map(function (a, index) { | ||
| return index; | ||
| }); | ||
| // This case still doesn't work because `reduce` has multiple overloads :( | ||
| arr.reduce(function (acc, a, index) { | ||
| return []; | ||
| }, []); | ||
| arr.forEach(function (a, index) { | ||
| return index; | ||
| }); | ||
| arr1.map(function (a, index) { | ||
| return index; | ||
| }); | ||
| arr1.reduce(function (acc, a, index) { | ||
| return [a]; | ||
| }, []); | ||
| arr1.forEach(function (a, index) { | ||
| return index; | ||
| }); | ||
| arr2.map(function (a, index) { | ||
| return index; | ||
| }); | ||
| arr2.reduce(function (acc, a, index) { | ||
| return []; | ||
| }, []); | ||
| arr2.forEach(function (a, index) { | ||
| return index; | ||
| }); | ||
| // note, you must annotate `result` for now | ||
| a.doThing().then(function (result) { | ||
| // whatever | ||
| }); |
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.
Interesting, it took me a second to grok what this was for. Would it have worked to just
instantiateSignature(right, mapper)and pass that in instead of instantiating each parameter type on demand?