TypeScript/tests/cases/conformance/generators/generatorReturnContextualType.ts
Andrew Branch 68ba670467
Add contextual type for generator return type (#39772)
* WIP

* Add contextual type for generator return type
2020-07-27 15:14:47 -07:00

22 lines
438 B
TypeScript

// @target: esnext
// @strict: true
// #35995
function* f1(): Generator<any, { x: 'x' }, any> {
return { x: 'x' };
}
async function* f2(): AsyncGenerator<any, { x: 'x' }, any> {
return { x: 'x' };
}
async function* f3(): AsyncGenerator<any, { x: 'x' }, any> {
return Promise.resolve({ x: 'x' });
}
async function* f4(): AsyncGenerator<any, { x: 'x' }, any> {
const ret = { x: 'x' };
return Promise.resolve(ret); // Error
}