Treat 'yield;' as 'yield undefined;' (#22297)
* Treat 'yield;' as 'yield undefined;' * Use undefinedWideningType
This commit is contained in:
parent
28e8c4f3b8
commit
e48bcd60ba
|
@ -18525,9 +18525,7 @@ namespace ts {
|
|||
const aggregatedTypes: Type[] = [];
|
||||
const isAsync = (getFunctionFlags(func) & FunctionFlags.Async) !== 0;
|
||||
forEachYieldExpression(<Block>func.body, yieldExpression => {
|
||||
if (yieldExpression.expression) { // TODO: GH#22297
|
||||
pushIfUnique(aggregatedTypes, getYieldedTypeOfYieldExpression(yieldExpression, isAsync, checkMode));
|
||||
}
|
||||
pushIfUnique(aggregatedTypes, getYieldedTypeOfYieldExpression(yieldExpression, isAsync, checkMode));
|
||||
});
|
||||
return aggregatedTypes;
|
||||
}
|
||||
|
@ -19520,8 +19518,6 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
if (!node.expression) return anyType; // TODO: GH#22297
|
||||
|
||||
const isAsync = (functionFlags & FunctionFlags.Async) !== 0;
|
||||
const yieldedType = getYieldedTypeOfYieldExpression(node, isAsync);
|
||||
// There is no point in doing an assignability check if the function
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts(1,9): error TS7025: Generator implicitly has type 'IterableIterator<any>' because it does not yield any values. Consider supplying a return type.
|
||||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts(1,11): error TS7010: 'g', which lacks return-type annotation, implicitly has an 'any' return type.
|
||||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts(5,11): error TS7010: 'h', which lacks return-type annotation, implicitly has an 'any' return type.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts (2 errors) ====
|
||||
function* g() {
|
||||
~
|
||||
!!! error TS7025: Generator implicitly has type 'IterableIterator<any>' because it does not yield any values. Consider supplying a return type.
|
||||
~
|
||||
!!! error TS7010: 'g', which lacks return-type annotation, implicitly has an 'any' return type.
|
||||
yield;
|
||||
}
|
||||
}
|
||||
|
||||
function* h() {
|
||||
~
|
||||
!!! error TS7010: 'h', which lacks return-type annotation, implicitly has an 'any' return type.
|
||||
yield undefined;
|
||||
}
|
||||
|
|
@ -1,9 +1,17 @@
|
|||
//// [generatorTypeCheck48.ts]
|
||||
function* g() {
|
||||
yield;
|
||||
}
|
||||
}
|
||||
|
||||
function* h() {
|
||||
yield undefined;
|
||||
}
|
||||
|
||||
|
||||
//// [generatorTypeCheck48.js]
|
||||
function* g() {
|
||||
yield;
|
||||
}
|
||||
function* h() {
|
||||
yield undefined;
|
||||
}
|
||||
|
|
|
@ -4,3 +4,11 @@ function* g() {
|
|||
|
||||
yield;
|
||||
}
|
||||
|
||||
function* h() {
|
||||
>h : Symbol(h, Decl(generatorTypeCheck48.ts, 2, 1))
|
||||
|
||||
yield undefined;
|
||||
>undefined : Symbol(undefined)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,3 +5,12 @@ function* g() {
|
|||
yield;
|
||||
>yield : any
|
||||
}
|
||||
|
||||
function* h() {
|
||||
>h : () => IterableIterator<any>
|
||||
|
||||
yield undefined;
|
||||
>yield undefined : any
|
||||
>undefined : undefined
|
||||
}
|
||||
|
||||
|
|
16
tests/baselines/reference/yieldExpression1.errors.txt
Normal file
16
tests/baselines/reference/yieldExpression1.errors.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
tests/cases/compiler/yieldExpression1.ts(7,5): error TS2322: Type 'undefined' is not assignable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/yieldExpression1.ts (1 errors) ====
|
||||
function* a() {
|
||||
yield;
|
||||
yield 0;
|
||||
}
|
||||
|
||||
function* b(): IterableIterator<number> {
|
||||
yield;
|
||||
~~~~~
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'number'.
|
||||
yield 0;
|
||||
}
|
||||
|
|
@ -1,9 +1,21 @@
|
|||
//// [yieldExpression1.ts]
|
||||
function* foo() {
|
||||
yield
|
||||
}
|
||||
function* a() {
|
||||
yield;
|
||||
yield 0;
|
||||
}
|
||||
|
||||
function* b(): IterableIterator<number> {
|
||||
yield;
|
||||
yield 0;
|
||||
}
|
||||
|
||||
|
||||
//// [yieldExpression1.js]
|
||||
function* foo() {
|
||||
function* a() {
|
||||
yield;
|
||||
yield 0;
|
||||
}
|
||||
function* b() {
|
||||
yield;
|
||||
yield 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
=== tests/cases/compiler/yieldExpression1.ts ===
|
||||
function* foo() {
|
||||
>foo : Symbol(foo, Decl(yieldExpression1.ts, 0, 0))
|
||||
function* a() {
|
||||
>a : Symbol(a, Decl(yieldExpression1.ts, 0, 0))
|
||||
|
||||
yield
|
||||
yield;
|
||||
yield 0;
|
||||
}
|
||||
|
||||
function* b(): IterableIterator<number> {
|
||||
>b : Symbol(b, Decl(yieldExpression1.ts, 3, 1))
|
||||
>IterableIterator : Symbol(IterableIterator, Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
|
||||
yield;
|
||||
yield 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,24 @@
|
|||
=== tests/cases/compiler/yieldExpression1.ts ===
|
||||
function* foo() {
|
||||
>foo : () => IterableIterator<any>
|
||||
function* a() {
|
||||
>a : () => IterableIterator<0 | undefined>
|
||||
|
||||
yield
|
||||
yield;
|
||||
>yield : any
|
||||
|
||||
yield 0;
|
||||
>yield 0 : any
|
||||
>0 : 0
|
||||
}
|
||||
|
||||
function* b(): IterableIterator<number> {
|
||||
>b : () => IterableIterator<number>
|
||||
>IterableIterator : IterableIterator<T>
|
||||
|
||||
yield;
|
||||
>yield : any
|
||||
|
||||
yield 0;
|
||||
>yield 0 : any
|
||||
>0 : 0
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
// @target: es6
|
||||
function* foo() {
|
||||
yield
|
||||
}
|
||||
// @strictNullChecks: true
|
||||
|
||||
function* a() {
|
||||
yield;
|
||||
yield 0;
|
||||
}
|
||||
|
||||
function* b(): IterableIterator<number> {
|
||||
yield;
|
||||
yield 0;
|
||||
}
|
||||
|
|
|
@ -3,4 +3,8 @@
|
|||
|
||||
function* g() {
|
||||
yield;
|
||||
}
|
||||
}
|
||||
|
||||
function* h() {
|
||||
yield undefined;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue