-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fixed an issue with self-referential awaited union #49677
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
jakebailey
merged 2 commits into
microsoft:main
from
Andarist:fix/self-referential-awaited-against-generic
Jun 29, 2022
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
30 changes: 30 additions & 0 deletions
30
tests/baselines/reference/unresolvableSelfReferencingAwaitedUnion.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,30 @@ | ||
tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts(9,32): error TS2322: Type 'SimpleType' is not assignable to type 'T'. | ||
'T' could be instantiated with an arbitrary type which could be unrelated to 'SimpleType'. | ||
tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts(16,19): error TS1062: Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method. | ||
|
||
|
||
==== tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts (2 errors) ==== | ||
// repro #49646 | ||
|
||
type EnvFunction = <T>() => T; | ||
|
||
type SimpleType = string | Promise<SimpleType>; | ||
|
||
declare const simple: SimpleType; | ||
|
||
const env: EnvFunction = () => simple; | ||
~~~~~~ | ||
!!! error TS2322: Type 'SimpleType' is not assignable to type 'T'. | ||
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'SimpleType'. | ||
!!! related TS6502 tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts:3:20: The expected type comes from the return type of this signature. | ||
|
||
// repro #49723 | ||
|
||
type T1 = 1 | Promise<T1> | T1[]; | ||
|
||
export async function myFunction(param: T1) { | ||
const awaited = await param | ||
~~~~~~~~~~~ | ||
!!! error TS1062: Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method. | ||
} | ||
|
40 changes: 40 additions & 0 deletions
40
tests/baselines/reference/unresolvableSelfReferencingAwaitedUnion.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,40 @@ | ||
=== tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.ts === | ||
// repro #49646 | ||
|
||
type EnvFunction = <T>() => T; | ||
>EnvFunction : Symbol(EnvFunction, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 0, 0)) | ||
>T : Symbol(T, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 2, 20)) | ||
>T : Symbol(T, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 2, 20)) | ||
|
||
type SimpleType = string | Promise<SimpleType>; | ||
>SimpleType : Symbol(SimpleType, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 2, 30)) | ||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --)) | ||
>SimpleType : Symbol(SimpleType, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 2, 30)) | ||
|
||
declare const simple: SimpleType; | ||
>simple : Symbol(simple, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 6, 13)) | ||
>SimpleType : Symbol(SimpleType, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 2, 30)) | ||
|
||
const env: EnvFunction = () => simple; | ||
>env : Symbol(env, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 8, 5)) | ||
>EnvFunction : Symbol(EnvFunction, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 0, 0)) | ||
>simple : Symbol(simple, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 6, 13)) | ||
|
||
// repro #49723 | ||
|
||
type T1 = 1 | Promise<T1> | T1[]; | ||
>T1 : Symbol(T1, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 8, 38)) | ||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --)) | ||
>T1 : Symbol(T1, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 8, 38)) | ||
>T1 : Symbol(T1, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 8, 38)) | ||
|
||
export async function myFunction(param: T1) { | ||
>myFunction : Symbol(myFunction, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 12, 33)) | ||
>param : Symbol(param, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 14, 33)) | ||
>T1 : Symbol(T1, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 8, 38)) | ||
|
||
const awaited = await param | ||
>awaited : Symbol(awaited, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 15, 7)) | ||
>param : Symbol(param, Decl(unresolvableSelfReferencingAwaitedUnion.ts, 14, 33)) | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/unresolvableSelfReferencingAwaitedUnion.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/unresolvableSelfReferencingAwaitedUnion.ts === | ||
// repro #49646 | ||
|
||
type EnvFunction = <T>() => T; | ||
>EnvFunction : <T>() => T | ||
|
||
type SimpleType = string | Promise<SimpleType>; | ||
>SimpleType : string | Promise<SimpleType> | ||
|
||
declare const simple: SimpleType; | ||
>simple : SimpleType | ||
|
||
const env: EnvFunction = () => simple; | ||
>env : EnvFunction | ||
>() => simple : () => SimpleType | ||
>simple : SimpleType | ||
|
||
// repro #49723 | ||
|
||
type T1 = 1 | Promise<T1> | T1[]; | ||
>T1 : 1 | Promise<T1> | T1[] | ||
|
||
export async function myFunction(param: T1) { | ||
>myFunction : (param: T1) => Promise<void> | ||
>param : T1 | ||
|
||
const awaited = await param | ||
>awaited : 1 | T1[] | ||
>await param : 1 | T1[] | ||
>param : T1 | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
tests/cases/compiler/unresolvableSelfReferencingAwaitedUnion.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,19 @@ | ||
// @noEmit: true | ||
|
||
// repro #49646 | ||
|
||
type EnvFunction = <T>() => T; | ||
|
||
type SimpleType = string | Promise<SimpleType>; | ||
|
||
declare const simple: SimpleType; | ||
|
||
const env: EnvFunction = () => simple; | ||
|
||
// repro #49723 | ||
|
||
type T1 = 1 | Promise<T1> | T1[]; | ||
|
||
export async function myFunction(param: T1) { | ||
const awaited = await param | ||
} |
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.
@jakebailey I've added the test case from your issue - note that the reported error is slightly different from the other one but I assume that's expected (since the other one was specific to generic functions and this ain't one)
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.
Yes, that's correct.