|
| 1 | +//// [tests/cases/compiler/asyncYieldStarContextualType.ts] //// |
| 2 | + |
| 3 | +=== asyncYieldStarContextualType.ts === |
| 4 | +// https://github.com/microsoft/TypeScript/issues/57903 |
| 5 | +interface Result<T, E> { |
| 6 | +>Result : Symbol(Result, Decl(asyncYieldStarContextualType.ts, 0, 0)) |
| 7 | +>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 1, 17)) |
| 8 | +>E : Symbol(E, Decl(asyncYieldStarContextualType.ts, 1, 19)) |
| 9 | + |
| 10 | + [Symbol.iterator](): Generator<E, T, unknown> |
| 11 | +>[Symbol.iterator] : Symbol(Result[Symbol.iterator], Decl(asyncYieldStarContextualType.ts, 1, 24)) |
| 12 | +>Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) |
| 13 | +>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, --, --)) |
| 14 | +>iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) |
| 15 | +>Generator : Symbol(Generator, Decl(lib.es2015.generator.d.ts, --, --)) |
| 16 | +>E : Symbol(E, Decl(asyncYieldStarContextualType.ts, 1, 19)) |
| 17 | +>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 1, 17)) |
| 18 | +} |
| 19 | + |
| 20 | +type Book = { id: string; title: string; authorId: string }; |
| 21 | +>Book : Symbol(Book, Decl(asyncYieldStarContextualType.ts, 3, 1)) |
| 22 | +>id : Symbol(id, Decl(asyncYieldStarContextualType.ts, 5, 13)) |
| 23 | +>title : Symbol(title, Decl(asyncYieldStarContextualType.ts, 5, 25)) |
| 24 | +>authorId : Symbol(authorId, Decl(asyncYieldStarContextualType.ts, 5, 40)) |
| 25 | + |
| 26 | +type Author = { id: string; name: string }; |
| 27 | +>Author : Symbol(Author, Decl(asyncYieldStarContextualType.ts, 5, 60)) |
| 28 | +>id : Symbol(id, Decl(asyncYieldStarContextualType.ts, 6, 15)) |
| 29 | +>name : Symbol(name, Decl(asyncYieldStarContextualType.ts, 6, 27)) |
| 30 | + |
| 31 | +type BookWithAuthor = Book & { author: Author }; |
| 32 | +>BookWithAuthor : Symbol(BookWithAuthor, Decl(asyncYieldStarContextualType.ts, 6, 43)) |
| 33 | +>Book : Symbol(Book, Decl(asyncYieldStarContextualType.ts, 3, 1)) |
| 34 | +>author : Symbol(author, Decl(asyncYieldStarContextualType.ts, 7, 30)) |
| 35 | +>Author : Symbol(Author, Decl(asyncYieldStarContextualType.ts, 5, 60)) |
| 36 | + |
| 37 | +declare const authorPromise: Promise<Result<Author, "NOT_FOUND_AUTHOR">>; |
| 38 | +>authorPromise : Symbol(authorPromise, Decl(asyncYieldStarContextualType.ts, 9, 13)) |
| 39 | +>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, --, --)) |
| 40 | +>Result : Symbol(Result, Decl(asyncYieldStarContextualType.ts, 0, 0)) |
| 41 | +>Author : Symbol(Author, Decl(asyncYieldStarContextualType.ts, 5, 60)) |
| 42 | + |
| 43 | +declare const mapper: <T>(result: Result<T, "NOT_FOUND_AUTHOR">) => Result<T, "NOT_FOUND_AUTHOR">; |
| 44 | +>mapper : Symbol(mapper, Decl(asyncYieldStarContextualType.ts, 10, 13)) |
| 45 | +>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 10, 23)) |
| 46 | +>result : Symbol(result, Decl(asyncYieldStarContextualType.ts, 10, 26)) |
| 47 | +>Result : Symbol(Result, Decl(asyncYieldStarContextualType.ts, 0, 0)) |
| 48 | +>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 10, 23)) |
| 49 | +>Result : Symbol(Result, Decl(asyncYieldStarContextualType.ts, 0, 0)) |
| 50 | +>T : Symbol(T, Decl(asyncYieldStarContextualType.ts, 10, 23)) |
| 51 | + |
| 52 | +async function* f(): AsyncGenerator<"NOT_FOUND_AUTHOR" | "NOT_FOUND_BOOK", BookWithAuthor, unknown> { |
| 53 | +>f : Symbol(f, Decl(asyncYieldStarContextualType.ts, 10, 98)) |
| 54 | +>AsyncGenerator : Symbol(AsyncGenerator, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) |
| 55 | +>BookWithAuthor : Symbol(BookWithAuthor, Decl(asyncYieldStarContextualType.ts, 6, 43)) |
| 56 | + |
| 57 | + // Without yield*, the type of test1 is |
| 58 | + // Result<Author, "NOT_FOUND_AUTHOR> |
| 59 | + const test1 = await authorPromise.then(mapper) |
| 60 | +>test1 : Symbol(test1, Decl(asyncYieldStarContextualType.ts, 15, 9)) |
| 61 | +>authorPromise.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) |
| 62 | +>authorPromise : Symbol(authorPromise, Decl(asyncYieldStarContextualType.ts, 9, 13)) |
| 63 | +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) |
| 64 | +>mapper : Symbol(mapper, Decl(asyncYieldStarContextualType.ts, 10, 13)) |
| 65 | + |
| 66 | + // With yield*, the type of test2 is |
| 67 | + // Author | BookWithAuthor |
| 68 | + // But this codepath has no way to produce BookWithAuthor |
| 69 | + const test2 = yield* await authorPromise.then(mapper) |
| 70 | +>test2 : Symbol(test2, Decl(asyncYieldStarContextualType.ts, 20, 9)) |
| 71 | +>authorPromise.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) |
| 72 | +>authorPromise : Symbol(authorPromise, Decl(asyncYieldStarContextualType.ts, 9, 13)) |
| 73 | +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) |
| 74 | +>mapper : Symbol(mapper, Decl(asyncYieldStarContextualType.ts, 10, 13)) |
| 75 | + |
| 76 | + return null! as BookWithAuthor; |
| 77 | +>BookWithAuthor : Symbol(BookWithAuthor, Decl(asyncYieldStarContextualType.ts, 6, 43)) |
| 78 | +} |
0 commit comments