Skip to content

Commit 03c6ee4

Browse files
committed
Add test cases from microsoft#56222
1 parent 6314401 commit 03c6ee4

4 files changed

+306
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
8+
type AsyncSequenceFactory = () => AsyncGenerator<string, string, string>;
9+
10+
type SequenceFactory = SyncSequenceFactory | AsyncSequenceFactory
11+
12+
const syncFactory: SyncSequenceFactory = function* (){
13+
let name = "";
14+
while(!name){
15+
name = yield "What is your name?"
16+
}
17+
return `That's the end of the game, ${name}`
18+
}
19+
20+
const asyncFactory: AsyncSequenceFactory = async function* (){
21+
let name = "";
22+
while(!name){
23+
name = yield "What is your name?"
24+
}
25+
return `That's the end of the game, ${name}`
26+
}
27+
28+
const looserSyncFactory: SequenceFactory = function* (){
29+
let name = "";
30+
while(!name){
31+
name = yield "What is your name?"
32+
}
33+
return `That's the end of the game, ${name}`
34+
}
35+
36+
const looserAsyncFactory: SequenceFactory = async function* (){
37+
let name = "";
38+
while(!name){
39+
name = yield "What is your name?"
40+
}
41+
return `That's the end of the game, ${name}`
42+
}
43+
44+
45+
//// [typeOfYieldWithUnionInContextualReturnType.js]
46+
// https://github.com/microsoft/TypeScript/issues/42439
47+
const syncFactory = function* () {
48+
let name = "";
49+
while (!name) {
50+
name = yield "What is your name?";
51+
}
52+
return `That's the end of the game, ${name}`;
53+
};
54+
const asyncFactory = async function* () {
55+
let name = "";
56+
while (!name) {
57+
name = yield "What is your name?";
58+
}
59+
return `That's the end of the game, ${name}`;
60+
};
61+
const looserSyncFactory = function* () {
62+
let name = "";
63+
while (!name) {
64+
name = yield "What is your name?";
65+
}
66+
return `That's the end of the game, ${name}`;
67+
};
68+
const looserAsyncFactory = async function* () {
69+
let name = "";
70+
while (!name) {
71+
name = yield "What is your name?";
72+
}
73+
return `That's the end of the game, ${name}`;
74+
};
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 : () => Generator<string, string, string>
8+
9+
type AsyncSequenceFactory = () => AsyncGenerator<string, string, string>;
10+
>AsyncSequenceFactory : () => AsyncGenerator<string, string, string>
11+
12+
type SequenceFactory = SyncSequenceFactory | AsyncSequenceFactory
13+
>SequenceFactory : SyncSequenceFactory | AsyncSequenceFactory
14+
15+
const syncFactory: SyncSequenceFactory = function* (){
16+
>syncFactory : SyncSequenceFactory
17+
>function* (){ let name = ""; while(!name){ name = yield "What is your name?" } return `That's the end of the game, ${name}`} : () => Generator<string, string, string>
18+
19+
let name = "";
20+
>name : string
21+
>"" : ""
22+
23+
while(!name){
24+
>!name : boolean
25+
>name : string
26+
27+
name = yield "What is your name?"
28+
>name = yield "What is your name?" : string
29+
>name : string
30+
>yield "What is your name?" : string
31+
>"What is your name?" : "What is your name?"
32+
}
33+
return `That's the end of the game, ${name}`
34+
>`That's the end of the game, ${name}` : string
35+
>name : string
36+
}
37+
38+
const asyncFactory: AsyncSequenceFactory = async function* (){
39+
>asyncFactory : AsyncSequenceFactory
40+
>async function* (){ let name = ""; while(!name){ name = yield "What is your name?" } return `That's the end of the game, ${name}`} : () => AsyncGenerator<string, string, string>
41+
42+
let name = "";
43+
>name : string
44+
>"" : ""
45+
46+
while(!name){
47+
>!name : boolean
48+
>name : string
49+
50+
name = yield "What is your name?"
51+
>name = yield "What is your name?" : string
52+
>name : string
53+
>yield "What is your name?" : string
54+
>"What is your name?" : "What is your name?"
55+
}
56+
return `That's the end of the game, ${name}`
57+
>`That's the end of the game, ${name}` : string
58+
>name : string
59+
}
60+
61+
const looserSyncFactory: SequenceFactory = function* (){
62+
>looserSyncFactory : SequenceFactory
63+
>function* (){ let name = ""; while(!name){ name = yield "What is your name?" } return `That's the end of the game, ${name}`} : () => Generator<string, string, string>
64+
65+
let name = "";
66+
>name : string
67+
>"" : ""
68+
69+
while(!name){
70+
>!name : boolean
71+
>name : string
72+
73+
name = yield "What is your name?"
74+
>name = yield "What is your name?" : string
75+
>name : string
76+
>yield "What is your name?" : string
77+
>"What is your name?" : "What is your name?"
78+
}
79+
return `That's the end of the game, ${name}`
80+
>`That's the end of the game, ${name}` : string
81+
>name : string
82+
}
83+
84+
const looserAsyncFactory: SequenceFactory = async function* (){
85+
>looserAsyncFactory : SequenceFactory
86+
>async function* (){ let name = ""; while(!name){ name = yield "What is your name?" } return `That's the end of the game, ${name}`} : () => AsyncGenerator<string, string, string>
87+
88+
let name = "";
89+
>name : string
90+
>"" : ""
91+
92+
while(!name){
93+
>!name : boolean
94+
>name : string
95+
96+
name = yield "What is your name?"
97+
>name = yield "What is your name?" : string
98+
>name : string
99+
>yield "What is your name?" : string
100+
>"What is your name?" : "What is your name?"
101+
}
102+
return `That's the end of the game, ${name}`
103+
>`That's the end of the game, ${name}` : string
104+
>name : string
105+
}
106+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// @target: esnext
2+
// https://github.com/microsoft/TypeScript/issues/42439
3+
4+
type SyncSequenceFactory = () => Generator<string, string, string>;
5+
6+
type AsyncSequenceFactory = () => AsyncGenerator<string, string, string>;
7+
8+
type SequenceFactory = SyncSequenceFactory | AsyncSequenceFactory
9+
10+
const syncFactory: SyncSequenceFactory = function* (){
11+
let name = "";
12+
while(!name){
13+
name = yield "What is your name?"
14+
}
15+
return `That's the end of the game, ${name}`
16+
}
17+
18+
const asyncFactory: AsyncSequenceFactory = async function* (){
19+
let name = "";
20+
while(!name){
21+
name = yield "What is your name?"
22+
}
23+
return `That's the end of the game, ${name}`
24+
}
25+
26+
const looserSyncFactory: SequenceFactory = function* (){
27+
let name = "";
28+
while(!name){
29+
name = yield "What is your name?"
30+
}
31+
return `That's the end of the game, ${name}`
32+
}
33+
34+
const looserAsyncFactory: SequenceFactory = async function* (){
35+
let name = "";
36+
while(!name){
37+
name = yield "What is your name?"
38+
}
39+
return `That's the end of the game, ${name}`
40+
}

0 commit comments

Comments
 (0)