-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Do not infer yield*
type from contextual TReturn
#58621
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 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
96 changes: 96 additions & 0 deletions
96
tests/baselines/reference/asyncYieldStarContextualType.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,96 @@ | ||
//// [tests/cases/compiler/asyncYieldStarContextualType.ts] //// | ||
|
||
=== asyncYieldStarContextualType.ts === | ||
// https://github.com/microsoft/TypeScript/issues/57903 | ||
interface Result<T, E> { | ||
>Result : Symbol(Result, Decl(asyncYieldStarContextualType.ts, 0, 0)) | ||
>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 1, 17)) | ||
>E : Symbol(E, Decl(asyncYieldStarContextualType.ts, 1, 19)) | ||
|
||
[Symbol.iterator](): Generator<E, T, unknown> | ||
>[Symbol.iterator] : Symbol(Result[Symbol.iterator], Decl(asyncYieldStarContextualType.ts, 1, 24)) | ||
>Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) | ||
>iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
>Generator : Symbol(Generator, Decl(lib.es2015.generator.d.ts, --, --)) | ||
>E : Symbol(E, Decl(asyncYieldStarContextualType.ts, 1, 19)) | ||
>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 1, 17)) | ||
} | ||
|
||
type Book = { id: string; title: string; authorId: string }; | ||
>Book : Symbol(Book, Decl(asyncYieldStarContextualType.ts, 3, 1)) | ||
>id : Symbol(id, Decl(asyncYieldStarContextualType.ts, 5, 13)) | ||
>title : Symbol(title, Decl(asyncYieldStarContextualType.ts, 5, 25)) | ||
>authorId : Symbol(authorId, Decl(asyncYieldStarContextualType.ts, 5, 40)) | ||
|
||
type Author = { id: string; name: string }; | ||
>Author : Symbol(Author, Decl(asyncYieldStarContextualType.ts, 5, 60)) | ||
>id : Symbol(id, Decl(asyncYieldStarContextualType.ts, 6, 15)) | ||
>name : Symbol(name, Decl(asyncYieldStarContextualType.ts, 6, 27)) | ||
|
||
type BookWithAuthor = Book & { author: Author }; | ||
>BookWithAuthor : Symbol(BookWithAuthor, Decl(asyncYieldStarContextualType.ts, 6, 43)) | ||
>Book : Symbol(Book, Decl(asyncYieldStarContextualType.ts, 3, 1)) | ||
>author : Symbol(author, Decl(asyncYieldStarContextualType.ts, 7, 30)) | ||
>Author : Symbol(Author, Decl(asyncYieldStarContextualType.ts, 5, 60)) | ||
|
||
declare const authorPromise: Promise<Result<Author, "NOT_FOUND_AUTHOR">>; | ||
>authorPromise : Symbol(authorPromise, Decl(asyncYieldStarContextualType.ts, 9, 13)) | ||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) | ||
>Result : Symbol(Result, Decl(asyncYieldStarContextualType.ts, 0, 0)) | ||
>Author : Symbol(Author, Decl(asyncYieldStarContextualType.ts, 5, 60)) | ||
|
||
declare const mapper: <T>(result: Result<T, "NOT_FOUND_AUTHOR">) => Result<T, "NOT_FOUND_AUTHOR">; | ||
>mapper : Symbol(mapper, Decl(asyncYieldStarContextualType.ts, 10, 13)) | ||
>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 10, 23)) | ||
>result : Symbol(result, Decl(asyncYieldStarContextualType.ts, 10, 26)) | ||
>Result : Symbol(Result, Decl(asyncYieldStarContextualType.ts, 0, 0)) | ||
>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 10, 23)) | ||
>Result : Symbol(Result, Decl(asyncYieldStarContextualType.ts, 0, 0)) | ||
>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 10, 23)) | ||
|
||
declare const g: <T, U, V>() => AsyncGenerator<T, U, V>; | ||
>g : Symbol(g, Decl(asyncYieldStarContextualType.ts, 11, 13)) | ||
>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 11, 18)) | ||
>U : Symbol(U, Decl(asyncYieldStarContextualType.ts, 11, 20)) | ||
>V : Symbol(V, Decl(asyncYieldStarContextualType.ts, 11, 23)) | ||
>AsyncGenerator : Symbol(AsyncGenerator, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) | ||
>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 11, 18)) | ||
>U : Symbol(U, Decl(asyncYieldStarContextualType.ts, 11, 20)) | ||
>V : Symbol(V, Decl(asyncYieldStarContextualType.ts, 11, 23)) | ||
|
||
async function* f(): AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", BookWithAuthor, unknown> { | ||
>f : Symbol(f, Decl(asyncYieldStarContextualType.ts, 11, 56)) | ||
>AsyncGenerator : Symbol(AsyncGenerator, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) | ||
>BookWithAuthor : Symbol(BookWithAuthor, Decl(asyncYieldStarContextualType.ts, 6, 43)) | ||
|
||
// Without yield*, the type of test1 is | ||
// Result<Author, "NOT_FOUND_AUTHOR> | ||
const test1 = await authorPromise.then(mapper) | ||
>test1 : Symbol(test1, Decl(asyncYieldStarContextualType.ts, 16, 9)) | ||
>authorPromise.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) | ||
>authorPromise : Symbol(authorPromise, Decl(asyncYieldStarContextualType.ts, 9, 13)) | ||
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) | ||
>mapper : Symbol(mapper, Decl(asyncYieldStarContextualType.ts, 10, 13)) | ||
|
||
// With yield*, the type of test2 is | ||
// Author | BookWithAuthor | ||
// But this codepath has no way to produce BookWithAuthor | ||
const test2 = yield* await authorPromise.then(mapper) | ||
>test2 : Symbol(test2, Decl(asyncYieldStarContextualType.ts, 21, 9)) | ||
>authorPromise.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) | ||
>authorPromise : Symbol(authorPromise, Decl(asyncYieldStarContextualType.ts, 9, 13)) | ||
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) | ||
>mapper : Symbol(mapper, Decl(asyncYieldStarContextualType.ts, 10, 13)) | ||
|
||
const x1 = yield* g(); | ||
>x1 : Symbol(x1, Decl(asyncYieldStarContextualType.ts, 23, 9)) | ||
>g : Symbol(g, Decl(asyncYieldStarContextualType.ts, 11, 13)) | ||
|
||
const x2: number = yield* g(); | ||
>x2 : Symbol(x2, Decl(asyncYieldStarContextualType.ts, 24, 9)) | ||
>g : Symbol(g, Decl(asyncYieldStarContextualType.ts, 11, 13)) | ||
|
||
return null! as BookWithAuthor; | ||
>BookWithAuthor : Symbol(BookWithAuthor, Decl(asyncYieldStarContextualType.ts, 6, 43)) | ||
} |
123 changes: 123 additions & 0 deletions
123
tests/baselines/reference/asyncYieldStarContextualType.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,123 @@ | ||
//// [tests/cases/compiler/asyncYieldStarContextualType.ts] //// | ||
|
||
=== asyncYieldStarContextualType.ts === | ||
// https://github.com/microsoft/TypeScript/issues/57903 | ||
interface Result<T, E> { | ||
[Symbol.iterator](): Generator<E, T, unknown> | ||
>[Symbol.iterator] : () => Generator<E, T, unknown> | ||
> : ^^^^^^ | ||
>Symbol.iterator : unique symbol | ||
> : ^^^^^^^^^^^^^ | ||
>Symbol : SymbolConstructor | ||
> : ^^^^^^^^^^^^^^^^^ | ||
>iterator : unique symbol | ||
> : ^^^^^^^^^^^^^ | ||
} | ||
|
||
type Book = { id: string; title: string; authorId: string }; | ||
>Book : Book | ||
> : ^^^^ | ||
>id : string | ||
> : ^^^^^^ | ||
>title : string | ||
> : ^^^^^^ | ||
>authorId : string | ||
> : ^^^^^^ | ||
|
||
type Author = { id: string; name: string }; | ||
>Author : Author | ||
> : ^^^^^^ | ||
>id : string | ||
> : ^^^^^^ | ||
>name : string | ||
> : ^^^^^^ | ||
|
||
type BookWithAuthor = Book & { author: Author }; | ||
>BookWithAuthor : BookWithAuthor | ||
> : ^^^^^^^^^^^^^^ | ||
>author : Author | ||
> : ^^^^^^ | ||
|
||
declare const authorPromise: Promise<Result<Author, "NOT_FOUND_AUTHOR">>; | ||
>authorPromise : Promise<Result<Author, "NOT_FOUND_AUTHOR">> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
declare const mapper: <T>(result: Result<T, "NOT_FOUND_AUTHOR">) => Result<T, "NOT_FOUND_AUTHOR">; | ||
>mapper : <T>(result: Result<T, "NOT_FOUND_AUTHOR">) => Result<T, "NOT_FOUND_AUTHOR"> | ||
> : ^ ^^ ^^ ^^^^^ | ||
>result : Result<T, "NOT_FOUND_AUTHOR"> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
declare const g: <T, U, V>() => AsyncGenerator<T, U, V>; | ||
>g : <T, U, V>() => AsyncGenerator<T, U, V> | ||
> : ^ ^^ ^^ ^^^^^^^ | ||
|
||
async function* f(): AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", BookWithAuthor, unknown> { | ||
>f : () => AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", BookWithAuthor, unknown> | ||
> : ^^^^^^ | ||
|
||
// Without yield*, the type of test1 is | ||
// Result<Author, "NOT_FOUND_AUTHOR> | ||
const test1 = await authorPromise.then(mapper) | ||
>test1 : Result<Author, "NOT_FOUND_AUTHOR"> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>await authorPromise.then(mapper) : Result<Author, "NOT_FOUND_AUTHOR"> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>authorPromise.then(mapper) : Promise<Result<Author, "NOT_FOUND_AUTHOR">> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>authorPromise.then : <TResult1 = Result<Author, "NOT_FOUND_AUTHOR">, TResult2 = never>(onfulfilled?: (value: Result<Author, "NOT_FOUND_AUTHOR">) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>authorPromise : Promise<Result<Author, "NOT_FOUND_AUTHOR">> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>then : <TResult1 = Result<Author, "NOT_FOUND_AUTHOR">, TResult2 = never>(onfulfilled?: (value: Result<Author, "NOT_FOUND_AUTHOR">) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>mapper : <T>(result: Result<T, "NOT_FOUND_AUTHOR">) => Result<T, "NOT_FOUND_AUTHOR"> | ||
> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
// With yield*, the type of test2 is | ||
// Author | BookWithAuthor | ||
// But this codepath has no way to produce BookWithAuthor | ||
const test2 = yield* await authorPromise.then(mapper) | ||
>test2 : Author | ||
> : ^^^^^^ | ||
>yield* await authorPromise.then(mapper) : Author | ||
> : ^^^^^^ | ||
>await authorPromise.then(mapper) : Result<Author, "NOT_FOUND_AUTHOR"> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>authorPromise.then(mapper) : Promise<Result<Author, "NOT_FOUND_AUTHOR">> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>authorPromise.then : <TResult1 = Result<Author, "NOT_FOUND_AUTHOR">, TResult2 = never>(onfulfilled?: (value: Result<Author, "NOT_FOUND_AUTHOR">) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>authorPromise : Promise<Result<Author, "NOT_FOUND_AUTHOR">> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>then : <TResult1 = Result<Author, "NOT_FOUND_AUTHOR">, TResult2 = never>(onfulfilled?: (value: Result<Author, "NOT_FOUND_AUTHOR">) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>mapper : <T>(result: Result<T, "NOT_FOUND_AUTHOR">) => Result<T, "NOT_FOUND_AUTHOR"> | ||
> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
const x1 = yield* g(); | ||
>x1 : unknown | ||
> : ^^^^^^^ | ||
>yield* g() : unknown | ||
> : ^^^^^^^ | ||
>g() : AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", unknown, unknown> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>g : <T, U, V>() => AsyncGenerator<T, U, V> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
const x2: number = yield* g(); | ||
>x2 : number | ||
> : ^^^^^^ | ||
>yield* g() : number | ||
> : ^^^^^^ | ||
>g() : AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", number, unknown> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>g : <T, U, V>() => AsyncGenerator<T, U, V> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
return null! as BookWithAuthor; | ||
>null! as BookWithAuthor : BookWithAuthor | ||
> : ^^^^^^^^^^^^^^ | ||
>null! : null | ||
> : ^^^^ | ||
} |
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,25 @@ | ||
//// [tests/cases/compiler/yieldStarContextualType.ts] //// | ||
|
||
=== yieldStarContextualType.ts === | ||
declare const g: <T, U, V>() => Generator<T, U, V>; | ||
>g : Symbol(g, Decl(yieldStarContextualType.ts, 0, 13)) | ||
>T : Symbol(T, Decl(yieldStarContextualType.ts, 0, 18)) | ||
>U : Symbol(U, Decl(yieldStarContextualType.ts, 0, 20)) | ||
>V : Symbol(V, Decl(yieldStarContextualType.ts, 0, 23)) | ||
>Generator : Symbol(Generator, Decl(lib.es2015.generator.d.ts, --, --)) | ||
>T : Symbol(T, Decl(yieldStarContextualType.ts, 0, 18)) | ||
>U : Symbol(U, Decl(yieldStarContextualType.ts, 0, 20)) | ||
>V : Symbol(V, Decl(yieldStarContextualType.ts, 0, 23)) | ||
|
||
function* f(): Generator<string, void, unknown> { | ||
>f : Symbol(f, Decl(yieldStarContextualType.ts, 0, 51)) | ||
>Generator : Symbol(Generator, Decl(lib.es2015.generator.d.ts, --, --)) | ||
|
||
const x1 = yield* g(); | ||
>x1 : Symbol(x1, Decl(yieldStarContextualType.ts, 3, 9)) | ||
>g : Symbol(g, Decl(yieldStarContextualType.ts, 0, 13)) | ||
|
||
const x2: number = yield* g(); | ||
>x2 : Symbol(x2, Decl(yieldStarContextualType.ts, 4, 9)) | ||
>g : Symbol(g, Decl(yieldStarContextualType.ts, 0, 13)) | ||
} |
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,31 @@ | ||
//// [tests/cases/compiler/yieldStarContextualType.ts] //// | ||
|
||
=== yieldStarContextualType.ts === | ||
declare const g: <T, U, V>() => Generator<T, U, V>; | ||
>g : <T, U, V>() => Generator<T, U, V> | ||
> : ^ ^^ ^^ ^^^^^^^ | ||
|
||
function* f(): Generator<string, void, unknown> { | ||
>f : () => Generator<string, void, unknown> | ||
> : ^^^^^^ | ||
|
||
const x1 = yield* g(); | ||
>x1 : unknown | ||
> : ^^^^^^^ | ||
>yield* g() : unknown | ||
> : ^^^^^^^ | ||
>g() : Generator<string, unknown, unknown> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>g : <T, U, V>() => Generator<T, U, V> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
const x2: number = yield* g(); | ||
>x2 : number | ||
> : ^^^^^^ | ||
>yield* g() : number | ||
> : ^^^^^^ | ||
>g() : Generator<string, number, unknown> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>g : <T, U, V>() => Generator<T, U, V> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
} |
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,31 @@ | ||
// @target: esnext | ||
// @noEmit: true | ||
|
||
// https://github.com/microsoft/TypeScript/issues/57903 | ||
interface Result<T, E> { | ||
[Symbol.iterator](): Generator<E, T, unknown> | ||
} | ||
|
||
type Book = { id: string; title: string; authorId: string }; | ||
type Author = { id: string; name: string }; | ||
type BookWithAuthor = Book & { author: Author }; | ||
|
||
declare const authorPromise: Promise<Result<Author, "NOT_FOUND_AUTHOR">>; | ||
declare const mapper: <T>(result: Result<T, "NOT_FOUND_AUTHOR">) => Result<T, "NOT_FOUND_AUTHOR">; | ||
declare const g: <T, U, V>() => AsyncGenerator<T, U, V>; | ||
|
||
async function* f(): AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", BookWithAuthor, unknown> { | ||
// Without yield*, the type of test1 is | ||
// Result<Author, "NOT_FOUND_AUTHOR> | ||
const test1 = await authorPromise.then(mapper) | ||
|
||
// With yield*, the type of test2 is | ||
// Author | BookWithAuthor | ||
// But this codepath has no way to produce BookWithAuthor | ||
const test2 = yield* await authorPromise.then(mapper) | ||
|
||
const x1 = yield* g(); | ||
const x2: number = yield* g(); | ||
|
||
return null! as BookWithAuthor; | ||
} |
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,9 @@ | ||
// @target: esnext | ||
// @noEmit: true | ||
|
||
declare const g: <T, U, V>() => Generator<T, U, V>; | ||
|
||
function* f(): Generator<string, void, unknown> { | ||
const x1 = yield* g(); | ||
const x2: number = yield* g(); | ||
} |
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.
Why do we fall back to
silentNeverType
?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 need to fall back to something we do not infer from, and a generator that doesn't
yield
otherwise infers aT
ofnever
.silentNeverType
is non-inferable, so it seemed like the correct choice.