-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Find first callable/constructable type in union when appropriate #26895
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
6 commits
Select commit
Hold shift + click to select a range
3d812ef
Added test.
DanielRosenwasser 289ae3c
Accepted baseleines.
DanielRosenwasser c5c594f
Try finding the first type with a call/construct signature when relat…
DanielRosenwasser cd399fb
Accepted baselines.
DanielRosenwasser d989e10
Renamed test.
DanielRosenwasser d067376
Accepted baselines.
DanielRosenwasser 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
40 changes: 40 additions & 0 deletions
40
tests/baselines/reference/errorsWithInvokablesInUnions01.errors.txt
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,40 @@ | ||
tests/cases/compiler/errorsWithInvokablesInUnions01.ts(14,12): error TS2322: Type '(x: string) => void' is not assignable to type 'ConstructableA | IDirectiveLinkFn<number> | IDirectivePrePost<number>'. | ||
Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn<number>'. | ||
Types of parameters 'x' and 'scope' are incompatible. | ||
Type 'number' is not assignable to type 'string'. | ||
tests/cases/compiler/errorsWithInvokablesInUnions01.ts(16,12): error TS2322: Type 'typeof ctor' is not assignable to type 'ConstructableA | IDirectiveLinkFn<number> | IDirectivePrePost<number>'. | ||
Type 'typeof ctor' is not assignable to type 'ConstructableA'. | ||
Type 'ctor' is not assignable to type '{ somePropA: any; }'. | ||
Property 'somePropA' is missing in type 'ctor'. | ||
|
||
|
||
==== tests/cases/compiler/errorsWithInvokablesInUnions01.ts (2 errors) ==== | ||
interface ConstructableA { | ||
new(): { somePropA: any }; | ||
} | ||
|
||
interface IDirectiveLinkFn<TScope> { | ||
(scope: TScope): void; | ||
} | ||
|
||
interface IDirectivePrePost<TScope> { | ||
pre?: IDirectiveLinkFn<TScope>; | ||
post?: IDirectiveLinkFn<TScope>; | ||
} | ||
|
||
export let blah: IDirectiveLinkFn<number> | ConstructableA | IDirectivePrePost<number> = (x: string) => {} | ||
~~~~ | ||
!!! error TS2322: Type '(x: string) => void' is not assignable to type 'ConstructableA | IDirectiveLinkFn<number> | IDirectivePrePost<number>'. | ||
!!! error TS2322: Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn<number>'. | ||
!!! error TS2322: Types of parameters 'x' and 'scope' are incompatible. | ||
!!! error TS2322: Type 'number' is not assignable to type 'string'. | ||
|
||
export let ctor: IDirectiveLinkFn<number> | ConstructableA | IDirectivePrePost<number> = class { | ||
~~~~ | ||
!!! error TS2322: Type 'typeof ctor' is not assignable to type 'ConstructableA | IDirectiveLinkFn<number> | IDirectivePrePost<number>'. | ||
!!! error TS2322: Type 'typeof ctor' is not assignable to type 'ConstructableA'. | ||
!!! error TS2322: Type 'ctor' is not assignable to type '{ somePropA: any; }'. | ||
!!! error TS2322: Property 'somePropA' is missing in type 'ctor'. | ||
someUnaccountedProp: any; | ||
} | ||
|
30 changes: 30 additions & 0 deletions
30
tests/baselines/reference/errorsWithInvokablesInUnions01.js
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,30 @@ | ||
//// [errorsWithInvokablesInUnions01.ts] | ||
interface ConstructableA { | ||
new(): { somePropA: any }; | ||
} | ||
|
||
interface IDirectiveLinkFn<TScope> { | ||
(scope: TScope): void; | ||
} | ||
|
||
interface IDirectivePrePost<TScope> { | ||
pre?: IDirectiveLinkFn<TScope>; | ||
post?: IDirectiveLinkFn<TScope>; | ||
} | ||
|
||
export let blah: IDirectiveLinkFn<number> | ConstructableA | IDirectivePrePost<number> = (x: string) => {} | ||
|
||
export let ctor: IDirectiveLinkFn<number> | ConstructableA | IDirectivePrePost<number> = class { | ||
someUnaccountedProp: any; | ||
} | ||
|
||
|
||
//// [errorsWithInvokablesInUnions01.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.blah = function (x) { }; | ||
exports.ctor = /** @class */ (function () { | ||
function class_1() { | ||
} | ||
return class_1; | ||
}()); |
49 changes: 49 additions & 0 deletions
49
tests/baselines/reference/errorsWithInvokablesInUnions01.symbols
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,49 @@ | ||
=== tests/cases/compiler/errorsWithInvokablesInUnions01.ts === | ||
interface ConstructableA { | ||
>ConstructableA : Symbol(ConstructableA, Decl(errorsWithInvokablesInUnions01.ts, 0, 0)) | ||
|
||
new(): { somePropA: any }; | ||
>somePropA : Symbol(somePropA, Decl(errorsWithInvokablesInUnions01.ts, 1, 10)) | ||
} | ||
|
||
interface IDirectiveLinkFn<TScope> { | ||
>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithInvokablesInUnions01.ts, 2, 1)) | ||
>TScope : Symbol(TScope, Decl(errorsWithInvokablesInUnions01.ts, 4, 27)) | ||
|
||
(scope: TScope): void; | ||
>scope : Symbol(scope, Decl(errorsWithInvokablesInUnions01.ts, 5, 5)) | ||
>TScope : Symbol(TScope, Decl(errorsWithInvokablesInUnions01.ts, 4, 27)) | ||
} | ||
|
||
interface IDirectivePrePost<TScope> { | ||
>IDirectivePrePost : Symbol(IDirectivePrePost, Decl(errorsWithInvokablesInUnions01.ts, 6, 1)) | ||
>TScope : Symbol(TScope, Decl(errorsWithInvokablesInUnions01.ts, 8, 28)) | ||
|
||
pre?: IDirectiveLinkFn<TScope>; | ||
>pre : Symbol(IDirectivePrePost.pre, Decl(errorsWithInvokablesInUnions01.ts, 8, 37)) | ||
>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithInvokablesInUnions01.ts, 2, 1)) | ||
>TScope : Symbol(TScope, Decl(errorsWithInvokablesInUnions01.ts, 8, 28)) | ||
|
||
post?: IDirectiveLinkFn<TScope>; | ||
>post : Symbol(IDirectivePrePost.post, Decl(errorsWithInvokablesInUnions01.ts, 9, 35)) | ||
>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithInvokablesInUnions01.ts, 2, 1)) | ||
>TScope : Symbol(TScope, Decl(errorsWithInvokablesInUnions01.ts, 8, 28)) | ||
} | ||
|
||
export let blah: IDirectiveLinkFn<number> | ConstructableA | IDirectivePrePost<number> = (x: string) => {} | ||
>blah : Symbol(blah, Decl(errorsWithInvokablesInUnions01.ts, 13, 10)) | ||
>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithInvokablesInUnions01.ts, 2, 1)) | ||
>ConstructableA : Symbol(ConstructableA, Decl(errorsWithInvokablesInUnions01.ts, 0, 0)) | ||
>IDirectivePrePost : Symbol(IDirectivePrePost, Decl(errorsWithInvokablesInUnions01.ts, 6, 1)) | ||
>x : Symbol(x, Decl(errorsWithInvokablesInUnions01.ts, 13, 90)) | ||
|
||
export let ctor: IDirectiveLinkFn<number> | ConstructableA | IDirectivePrePost<number> = class { | ||
>ctor : Symbol(ctor, Decl(errorsWithInvokablesInUnions01.ts, 15, 10)) | ||
>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithInvokablesInUnions01.ts, 2, 1)) | ||
>ConstructableA : Symbol(ConstructableA, Decl(errorsWithInvokablesInUnions01.ts, 0, 0)) | ||
>IDirectivePrePost : Symbol(IDirectivePrePost, Decl(errorsWithInvokablesInUnions01.ts, 6, 1)) | ||
|
||
someUnaccountedProp: any; | ||
>someUnaccountedProp : Symbol(ctor.someUnaccountedProp, Decl(errorsWithInvokablesInUnions01.ts, 15, 96)) | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/errorsWithInvokablesInUnions01.types
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,32 @@ | ||
=== tests/cases/compiler/errorsWithInvokablesInUnions01.ts === | ||
interface ConstructableA { | ||
new(): { somePropA: any }; | ||
>somePropA : any | ||
} | ||
|
||
interface IDirectiveLinkFn<TScope> { | ||
(scope: TScope): void; | ||
>scope : TScope | ||
} | ||
|
||
interface IDirectivePrePost<TScope> { | ||
pre?: IDirectiveLinkFn<TScope>; | ||
>pre : IDirectiveLinkFn<TScope> | ||
|
||
post?: IDirectiveLinkFn<TScope>; | ||
>post : IDirectiveLinkFn<TScope> | ||
} | ||
|
||
export let blah: IDirectiveLinkFn<number> | ConstructableA | IDirectivePrePost<number> = (x: string) => {} | ||
>blah : ConstructableA | IDirectiveLinkFn<number> | IDirectivePrePost<number> | ||
>(x: string) => {} : (x: string) => void | ||
>x : string | ||
|
||
export let ctor: IDirectiveLinkFn<number> | ConstructableA | IDirectivePrePost<number> = class { | ||
>ctor : ConstructableA | IDirectiveLinkFn<number> | IDirectivePrePost<number> | ||
>class { someUnaccountedProp: any;} : typeof ctor | ||
|
||
someUnaccountedProp: any; | ||
>someUnaccountedProp : any | ||
} | ||
|
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,18 @@ | ||
interface ConstructableA { | ||
new(): { somePropA: any }; | ||
} | ||
|
||
interface IDirectiveLinkFn<TScope> { | ||
(scope: TScope): void; | ||
} | ||
|
||
interface IDirectivePrePost<TScope> { | ||
pre?: IDirectiveLinkFn<TScope>; | ||
post?: IDirectiveLinkFn<TScope>; | ||
} | ||
|
||
export let blah: IDirectiveLinkFn<number> | ConstructableA | IDirectivePrePost<number> = (x: string) => {} | ||
|
||
export let ctor: IDirectiveLinkFn<number> | ConstructableA | IDirectivePrePost<number> = class { | ||
someUnaccountedProp: any; | ||
} |
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.
We could avoid these baseline changes if we choose the last matching invokable instead of the first.