TypeScript Version: 3.7.2
Search Terms:
Expected behavior:
let barGenerator: Generator<any, string, { name: string; } | { age: number; }>;
Actual behavior:
let barGenerator: Generator<any, string, { name: string; } & { age: number; }>;
Related Issues:
Code
function* Bar() {
let x: { name: string } = yield;
let y: { age: number } = yield;
return x.name + y.age;
}
let barGenerator = Bar();
// let barGenerator: Generator<any, string, { name: string; } & { age: number; }>;
let barResult = barGenerator.next();
barResult = barGenerator.next({ name: "Bar" }); // Error: Argument of type '[{ name: string; }]' is not assignable to parameter of type '[] | [{ name: string; } & { age: number; }]'.
barResult = barGenerator.next({ age: 40 });
console.log(barResult);
Output
"use strict";
function* Bar() {
let x = yield;
let y = yield;
return x.name + y.age;
}
let barGenerator = Bar();
//let barGenerator: Generator<any, string, { name: string; } & { age: number; }>
let barResult = barGenerator.next();
// Error: Argument of type '[{ name: string; }]' is not assignable to parameter of type '[] | [{ name: string; } & { age: number; }]'.
barResult = barGenerator.next({ name: "Bar" });
barResult = barGenerator.next({ age: 40 });
console.log(barResult);
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"useDefineForClassFields": false,
"alwaysStrict": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"downlevelIteration": false,
"noEmitHelpers": false,
"noLib": false,
"noStrictGenericChecks": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"esModuleInterop": true,
"preserveConstEnums": false,
"removeComments": false,
"skipLibCheck": false,
"checkJs": false,
"allowJs": false,
"declaration": true,
"experimentalDecorators": false,
"emitDecoratorMetadata": false,
"target": "ES2017",
"module": "ESNext"
}
}
Playground Link: Provided
TypeScript Version: 3.7.2
Search Terms:
Expected behavior:
Actual behavior:
Related Issues:
Code
Output
Compiler Options
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true, "strictFunctionTypes": true, "strictPropertyInitialization": true, "strictBindCallApply": true, "noImplicitThis": true, "noImplicitReturns": true, "useDefineForClassFields": false, "alwaysStrict": true, "allowUnreachableCode": false, "allowUnusedLabels": false, "downlevelIteration": false, "noEmitHelpers": false, "noLib": false, "noStrictGenericChecks": false, "noUnusedLocals": false, "noUnusedParameters": false, "esModuleInterop": true, "preserveConstEnums": false, "removeComments": false, "skipLibCheck": false, "checkJs": false, "allowJs": false, "declaration": true, "experimentalDecorators": false, "emitDecoratorMetadata": false, "target": "ES2017", "module": "ESNext" } }Playground Link: Provided