|
| 1 | +//// [tests/cases/compiler/typeOfYieldWithUnionInContextualReturnType.ts] //// |
| 2 | + |
| 3 | +=== typeOfYieldWithUnionInContextualReturnType.ts === |
| 4 | +// https://github.com/microsoft/TypeScript/issues/42439 |
| 5 | + |
| 6 | +type SyncSequenceFactory = () => Generator<string, string, string>; |
| 7 | +>SyncSequenceFactory : Symbol(SyncSequenceFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 0, 0)) |
| 8 | +>Generator : Symbol(Generator, Decl(lib.es2015.generator.d.ts, --, --)) |
| 9 | + |
| 10 | +type AsyncSequenceFactory = () => AsyncGenerator<string, string, string>; |
| 11 | +>AsyncSequenceFactory : Symbol(AsyncSequenceFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 2, 67)) |
| 12 | +>AsyncGenerator : Symbol(AsyncGenerator, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) |
| 13 | + |
| 14 | +type SequenceFactory = SyncSequenceFactory | AsyncSequenceFactory |
| 15 | +>SequenceFactory : Symbol(SequenceFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 4, 73)) |
| 16 | +>SyncSequenceFactory : Symbol(SyncSequenceFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 0, 0)) |
| 17 | +>AsyncSequenceFactory : Symbol(AsyncSequenceFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 2, 67)) |
| 18 | + |
| 19 | +const syncFactory: SyncSequenceFactory = function* (){ |
| 20 | +>syncFactory : Symbol(syncFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 8, 5)) |
| 21 | +>SyncSequenceFactory : Symbol(SyncSequenceFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 0, 0)) |
| 22 | + |
| 23 | + let name = ""; |
| 24 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 9, 5)) |
| 25 | + |
| 26 | + while(!name){ |
| 27 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 9, 5)) |
| 28 | + |
| 29 | + name = yield "What is your name?" |
| 30 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 9, 5)) |
| 31 | + } |
| 32 | + return `That's the end of the game, ${name}` |
| 33 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 9, 5)) |
| 34 | +} |
| 35 | + |
| 36 | +const asyncFactory: AsyncSequenceFactory = async function* (){ |
| 37 | +>asyncFactory : Symbol(asyncFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 16, 5)) |
| 38 | +>AsyncSequenceFactory : Symbol(AsyncSequenceFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 2, 67)) |
| 39 | + |
| 40 | + let name = ""; |
| 41 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 17, 5)) |
| 42 | + |
| 43 | + while(!name){ |
| 44 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 17, 5)) |
| 45 | + |
| 46 | + name = yield "What is your name?" |
| 47 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 17, 5)) |
| 48 | + } |
| 49 | + return `That's the end of the game, ${name}` |
| 50 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 17, 5)) |
| 51 | +} |
| 52 | + |
| 53 | +const looserSyncFactory: SequenceFactory = function* (){ |
| 54 | +>looserSyncFactory : Symbol(looserSyncFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 24, 5)) |
| 55 | +>SequenceFactory : Symbol(SequenceFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 4, 73)) |
| 56 | + |
| 57 | + let name = ""; |
| 58 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 25, 5)) |
| 59 | + |
| 60 | + while(!name){ |
| 61 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 25, 5)) |
| 62 | + |
| 63 | + name = yield "What is your name?" |
| 64 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 25, 5)) |
| 65 | + } |
| 66 | + return `That's the end of the game, ${name}` |
| 67 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 25, 5)) |
| 68 | +} |
| 69 | + |
| 70 | +const looserAsyncFactory: SequenceFactory = async function* (){ |
| 71 | +>looserAsyncFactory : Symbol(looserAsyncFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 32, 5)) |
| 72 | +>SequenceFactory : Symbol(SequenceFactory, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 4, 73)) |
| 73 | + |
| 74 | + let name = ""; |
| 75 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 33, 5)) |
| 76 | + |
| 77 | + while(!name){ |
| 78 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 33, 5)) |
| 79 | + |
| 80 | + name = yield "What is your name?" |
| 81 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 33, 5)) |
| 82 | + } |
| 83 | + return `That's the end of the game, ${name}` |
| 84 | +>name : Symbol(name, Decl(typeOfYieldWithUnionInContextualReturnType.ts, 33, 5)) |
| 85 | +} |
| 86 | + |
0 commit comments