Skip to content

Commit 3e7a481

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

File tree

8 files changed

+52
-6
lines changed

8 files changed

+52
-6
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
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

tests/baselines/reference/generatorES6InAMDModule.types

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
Lines changed: 17 additions & 0 deletions
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+
Lines changed: 9 additions & 1 deletion
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

Lines changed: 8 additions & 0 deletions
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+
Lines changed: 10 additions & 1 deletion
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/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts

Lines changed: 5 additions & 1 deletion
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)