Skip to content

Commit f910468

Browse files
author
Andy Hanson
committed
Use undefinedWideningType
1 parent 2fbcd36 commit f910468

29 files changed

+96
-50
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18389,7 +18389,7 @@ namespace ts {
1838918389

1839018390
function getYieldedTypeOfYieldExpression(node: YieldExpression, isAsync: boolean, checkMode?: CheckMode): Type {
1839118391
const errorNode = node.expression || node;
18392-
const expressionType = node.expression ? checkExpressionCached(node.expression, checkMode) : undefinedType;
18392+
const expressionType = node.expression ? checkExpressionCached(node.expression, checkMode) : undefinedWideningType;
1839318393
// A yield* expression effectively yields everything that its operand yields
1839418394
const yieldedType = node.asteriskToken ? checkIteratedTypeOrElementType(expressionType, errorNode, /*allowStringInput*/ false, isAsync) : expressionType;
1839518395
return !isAsync ? yieldedType : getAwaitedType(yieldedType, errorNode, node.asteriskToken
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
=== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts ===
22
function * foo() {
3-
>foo : () => IterableIterator<undefined>
3+
>foo : () => IterableIterator<any>
44

55
var v = { [yield]: foo }
6-
>v : { [x: number]: () => IterableIterator<undefined>; }
7-
>{ [yield]: foo } : { [x: number]: () => IterableIterator<undefined>; }
8-
>[yield] : () => IterableIterator<undefined>
6+
>v : { [x: number]: () => IterableIterator<any>; }
7+
>{ [yield]: foo } : { [x: number]: () => IterableIterator<any>; }
8+
>[yield] : () => IterableIterator<any>
99
>yield : any
10-
>foo : () => IterableIterator<undefined>
10+
>foo : () => IterableIterator<any>
1111
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
=== tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts ===
22
function* foo() { yield }
3-
>foo : () => IterableIterator<undefined>
3+
>foo : () => IterableIterator<any>
44
>yield : any
55

tests/baselines/reference/YieldExpression3_es6.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts ===
22
function* foo() {
3-
>foo : () => IterableIterator<undefined>
3+
>foo : () => IterableIterator<any>
44

55
yield
66
>yield : any

tests/baselines/reference/YieldExpression4_es6.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts ===
22
function* foo() {
3-
>foo : () => IterableIterator<undefined>
3+
>foo : () => IterableIterator<any>
44

55
yield;
66
>yield : any

tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class C2 {
1111
>C2 : C2
1212

1313
async * f() {
14-
>f : () => AsyncIterableIterator<undefined>
14+
>f : () => AsyncIterableIterator<any>
1515

1616
const x = yield;
1717
>x : any

tests/baselines/reference/emitter.asyncGenerators.classMethods.es5.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class C2 {
1111
>C2 : C2
1212

1313
async * f() {
14-
>f : () => AsyncIterableIterator<undefined>
14+
>f : () => AsyncIterableIterator<any>
1515

1616
const x = yield;
1717
>x : any

tests/baselines/reference/emitter.asyncGenerators.classMethods.esnext.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class C2 {
1111
>C2 : C2
1212

1313
async * f() {
14-
>f : () => AsyncIterableIterator<undefined>
14+
>f : () => AsyncIterableIterator<any>
1515

1616
const x = yield;
1717
>x : any

tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es2015.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ async function * f1() {
44
}
55
=== tests/cases/conformance/emitter/es2015/asyncGenerators/F2.ts ===
66
async function * f2() {
7-
>f2 : () => AsyncIterableIterator<undefined>
7+
>f2 : () => AsyncIterableIterator<any>
88

99
const x = yield;
1010
>x : any

tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es5.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ async function * f1() {
44
}
55
=== tests/cases/conformance/emitter/es5/asyncGenerators/F2.ts ===
66
async function * f2() {
7-
>f2 : () => AsyncIterableIterator<undefined>
7+
>f2 : () => AsyncIterableIterator<any>
88

99
const x = yield;
1010
>x : any

tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.esnext.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ async function * f1() {
44
}
55
=== tests/cases/conformance/emitter/esnext/asyncGenerators/F2.ts ===
66
async function * f2() {
7-
>f2 : () => AsyncIterableIterator<undefined>
7+
>f2 : () => AsyncIterableIterator<any>
88

99
const x = yield;
1010
>x : any

tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es2015.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const f1 = async function * () {
55
}
66
=== tests/cases/conformance/emitter/es2015/asyncGenerators/F2.ts ===
77
const f2 = async function * () {
8-
>f2 : () => AsyncIterableIterator<undefined>
9-
>async function * () { const x = yield;} : () => AsyncIterableIterator<undefined>
8+
>f2 : () => AsyncIterableIterator<any>
9+
>async function * () { const x = yield;} : () => AsyncIterableIterator<any>
1010

1111
const x = yield;
1212
>x : any

tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es5.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const f1 = async function * () {
55
}
66
=== tests/cases/conformance/emitter/es5/asyncGenerators/F2.ts ===
77
const f2 = async function * () {
8-
>f2 : () => AsyncIterableIterator<undefined>
9-
>async function * () { const x = yield;} : () => AsyncIterableIterator<undefined>
8+
>f2 : () => AsyncIterableIterator<any>
9+
>async function * () { const x = yield;} : () => AsyncIterableIterator<any>
1010

1111
const x = yield;
1212
>x : any

tests/baselines/reference/emitter.asyncGenerators.functionExpressions.esnext.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const f1 = async function * () {
55
}
66
=== tests/cases/conformance/emitter/esnext/asyncGenerators/F2.ts ===
77
const f2 = async function * () {
8-
>f2 : () => AsyncIterableIterator<undefined>
9-
>async function * () { const x = yield;} : () => AsyncIterableIterator<undefined>
8+
>f2 : () => AsyncIterableIterator<any>
9+
>async function * () { const x = yield;} : () => AsyncIterableIterator<any>
1010

1111
const x = yield;
1212
>x : any

tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.es2015.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const o1 = {
99
}
1010
=== tests/cases/conformance/emitter/es2015/asyncGenerators/O2.ts ===
1111
const o2 = {
12-
>o2 : { f(): AsyncIterableIterator<undefined>; }
13-
>{ async * f() { const x = yield; }} : { f(): AsyncIterableIterator<undefined>; }
12+
>o2 : { f(): AsyncIterableIterator<any>; }
13+
>{ async * f() { const x = yield; }} : { f(): AsyncIterableIterator<any>; }
1414

1515
async * f() {
16-
>f : () => AsyncIterableIterator<undefined>
16+
>f : () => AsyncIterableIterator<any>
1717

1818
const x = yield;
1919
>x : any

tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.es5.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const o1 = {
99
}
1010
=== tests/cases/conformance/emitter/es5/asyncGenerators/O2.ts ===
1111
const o2 = {
12-
>o2 : { f(): AsyncIterableIterator<undefined>; }
13-
>{ async * f() { const x = yield; }} : { f(): AsyncIterableIterator<undefined>; }
12+
>o2 : { f(): AsyncIterableIterator<any>; }
13+
>{ async * f() { const x = yield; }} : { f(): AsyncIterableIterator<any>; }
1414

1515
async * f() {
16-
>f : () => AsyncIterableIterator<undefined>
16+
>f : () => AsyncIterableIterator<any>
1717

1818
const x = yield;
1919
>x : any

tests/baselines/reference/emitter.asyncGenerators.objectLiteralMethods.esnext.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const o1 = {
99
}
1010
=== tests/cases/conformance/emitter/esnext/asyncGenerators/O2.ts ===
1111
const o2 = {
12-
>o2 : { f(): AsyncIterableIterator<undefined>; }
13-
>{ async * f() { const x = yield; }} : { f(): AsyncIterableIterator<undefined>; }
12+
>o2 : { f(): AsyncIterableIterator<any>; }
13+
>{ async * f() { const x = yield; }} : { f(): AsyncIterableIterator<any>; }
1414

1515
async * f() {
16-
>f : () => AsyncIterableIterator<undefined>
16+
>f : () => AsyncIterableIterator<any>
1717

1818
const x = yield;
1919
>x : any

tests/baselines/reference/generatorES6InAMDModule.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/compiler/generatorES6InAMDModule.ts ===
22
export function* foo() {
3-
>foo : () => IterableIterator<undefined>
3+
>foo : () => IterableIterator<any>
44

55
yield
66
>yield : any

tests/baselines/reference/generatorES6_1.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/compiler/generatorES6_1.ts ===
22
function* foo() {
3-
>foo : () => IterableIterator<undefined>
3+
>foo : () => IterableIterator<any>
44

55
yield
66
>yield : any
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts(1,11): error TS7010: 'g', which lacks return-type annotation, implicitly has an 'any' return type.
2+
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts(5,11): error TS7010: 'h', which lacks return-type annotation, implicitly has an 'any' return type.
3+
4+
5+
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts (2 errors) ====
6+
function* g() {
7+
~
8+
!!! error TS7010: 'g', which lacks return-type annotation, implicitly has an 'any' return type.
9+
yield;
10+
}
11+
12+
function* h() {
13+
~
14+
!!! error TS7010: 'h', which lacks return-type annotation, implicitly has an 'any' return type.
15+
yield undefined;
16+
}
17+
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
//// [generatorTypeCheck48.ts]
22
function* g() {
33
yield;
4-
}
4+
}
5+
6+
function* h() {
7+
yield undefined;
8+
}
9+
510

611
//// [generatorTypeCheck48.js]
712
function* g() {
813
yield;
914
}
15+
function* h() {
16+
yield undefined;
17+
}

tests/baselines/reference/generatorTypeCheck48.symbols

+8
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ function* g() {
44

55
yield;
66
}
7+
8+
function* h() {
9+
>h : Symbol(h, Decl(generatorTypeCheck48.ts, 2, 1))
10+
11+
yield undefined;
12+
>undefined : Symbol(undefined)
13+
}
14+
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts ===
22
function* g() {
3-
>g : () => IterableIterator<undefined>
3+
>g : () => IterableIterator<any>
44

55
yield;
66
>yield : any
77
}
8+
9+
function* h() {
10+
>h : () => IterableIterator<any>
11+
12+
yield undefined;
13+
>yield undefined : any
14+
>undefined : undefined
15+
}
16+

tests/baselines/reference/parser.asyncGenerators.classMethods.esnext.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class C13 {
140140
>C13 : C13
141141

142142
async * f() {
143-
>f : () => AsyncIterableIterator<undefined>
143+
>f : () => AsyncIterableIterator<any>
144144

145145
yield;
146146
>yield : any
@@ -250,7 +250,7 @@ class C22 {
250250
>C22 : C22
251251

252252
async * f() {
253-
>f : () => AsyncIterableIterator<undefined>
253+
>f : () => AsyncIterableIterator<any>
254254

255255
const x = { [yield]: 1 };
256256
>x : { [x: number]: number; }

tests/baselines/reference/parser.asyncGenerators.functionDeclarations.esnext.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async function * f12() {
8888
}
8989
=== tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldIsOk.ts ===
9090
async function * f13() {
91-
>f13 : () => AsyncIterableIterator<undefined>
91+
>f13 : () => AsyncIterableIterator<any>
9292

9393
yield;
9494
>yield : any
@@ -157,7 +157,7 @@ async function * f20() {
157157
}
158158
=== tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldInNestedComputedPropertyIsOk.ts ===
159159
async function * f21() {
160-
>f21 : () => AsyncIterableIterator<undefined>
160+
>f21 : () => AsyncIterableIterator<any>
161161

162162
const x = { [yield]: 1 };
163163
>x : { [x: number]: number; }

tests/baselines/reference/parser.asyncGenerators.functionExpressions.esnext.types

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ const f12 = async function * () {
113113
};
114114
=== tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldIsOk.ts ===
115115
const f13 = async function * () {
116-
>f13 : () => AsyncIterableIterator<undefined>
117-
>async function * () { yield;} : () => AsyncIterableIterator<undefined>
116+
>f13 : () => AsyncIterableIterator<any>
117+
>async function * () { yield;} : () => AsyncIterableIterator<any>
118118

119119
yield;
120120
>yield : any
@@ -198,8 +198,8 @@ const f20 = async function * () {
198198
};
199199
=== tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldInNestedComputedPropertyIsOk.ts ===
200200
const f21 = async function *() {
201-
>f21 : () => AsyncIterableIterator<undefined>
202-
>async function *() { const x = { [yield]: 1 };} : () => AsyncIterableIterator<undefined>
201+
>f21 : () => AsyncIterableIterator<any>
202+
>async function *() { const x = { [yield]: 1 };} : () => AsyncIterableIterator<any>
203203

204204
const x = { [yield]: 1 };
205205
>x : { [x: number]: number; }

tests/baselines/reference/parser.asyncGenerators.objectLiteralMethods.esnext.types

+6-6
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ const o12 = {
151151
};
152152
=== tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldIsOk.ts ===
153153
const o13 = {
154-
>o13 : { f(): AsyncIterableIterator<undefined>; }
155-
>{ async * f() { yield; }} : { f(): AsyncIterableIterator<undefined>; }
154+
>o13 : { f(): AsyncIterableIterator<any>; }
155+
>{ async * f() { yield; }} : { f(): AsyncIterableIterator<any>; }
156156

157157
async * f() {
158-
>f : () => AsyncIterableIterator<undefined>
158+
>f : () => AsyncIterableIterator<any>
159159

160160
yield;
161161
>yield : any
@@ -260,11 +260,11 @@ const o20 = {
260260
};
261261
=== tests/cases/conformance/parser/ecmascriptnext/asyncGenerators/yieldInNestedComputedPropertyIsOk.ts ===
262262
const o21 = {
263-
>o21 : { f(): AsyncIterableIterator<undefined>; }
264-
>{ async * f() { const x = { [yield]: 1 }; }} : { f(): AsyncIterableIterator<undefined>; }
263+
>o21 : { f(): AsyncIterableIterator<any>; }
264+
>{ async * f() { const x = { [yield]: 1 }; }} : { f(): AsyncIterableIterator<any>; }
265265

266266
async * f() {
267-
>f : () => AsyncIterableIterator<undefined>
267+
>f : () => AsyncIterableIterator<any>
268268

269269
const x = { [yield]: 1 };
270270
>x : { [x: number]: number; }

tests/baselines/reference/types.asyncGenerators.esnext.1.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ async function * inferReturnType1() {
33
>inferReturnType1 : () => AsyncIterableIterator<any>
44
}
55
async function * inferReturnType2() {
6-
>inferReturnType2 : () => AsyncIterableIterator<undefined>
6+
>inferReturnType2 : () => AsyncIterableIterator<any>
77

88
yield;
99
>yield : any

tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33

44
function* g() {
55
yield;
6-
}
6+
}
7+
8+
function* h() {
9+
yield undefined;
10+
}

0 commit comments

Comments
 (0)