-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Description
Bug Report
There's a regression with unions is introduced in typescript 4.2
π Search Terms
union, spread, 4.2
π Version & Regression Information
- This changed between versions 4.1.5 and 4.2.2
β― Playground Link
Playground link with relevant code
π» Code
type A = {
prop1?: undefined;
prop2?: undefined;
} | {
prop1: string;
prop2?: string;
};
const b: A = { prop1: 'p1', prop2: 'p2' };
const a: A = {
...b ? b : {}
};π Actual behavior
Error:
const a: A
Type '{ prop1?: string | undefined; prop2?: string | undefined; }' is not assignable to type 'A'.
Type '{ prop1?: string | undefined; prop2?: string | undefined; }' is not assignable to type '{ prop1: string; prop2?: string | undefined; }'.
Types of property 'prop1' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.(2322)
π Expected behavior
No errors
ts 4.1.5 works as expected, without errors
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript