Skip to content

Wrong compilation error in type combining intersection of unions #31556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arnauorriols opened this issue May 23, 2019 · 1 comment
Closed

Wrong compilation error in type combining intersection of unions #31556

arnauorriols opened this issue May 23, 2019 · 1 comment
Labels
Bug A bug in TypeScript
Milestone

Comments

@arnauorriols
Copy link

arnauorriols commented May 23, 2019

TypeScript Version: typescript@3.5.0-dev.20190523

Search Terms: "intersection of unions"

Code

type Foo = (A | B) & (C | D);

interface A {
	a: true;
}

interface B {
	a: false;
}

interface C {
	b: "foo";
}

interface D {
	b: "bar";
}

const foo: Foo = {
	a: true,
	// b: "foo"
};

Expected behavior: Compilation error:

Property 'b' is missing in type '{ name: string; a: true}' but required in type 'C'.

Actual behavior: Compilation error:

test.ts(19,7): error TS2322: Type '{ a: true; }' is not assignable to type 'Foo'.
Type '{ a: true; }' is not assignable to type 'B & D'.
Type '{ a: true; }' is not assignable to type 'B'.
Types of property 'a' are incompatible.
Type 'true' is not assignable to type 'false'.

If // b: "foo" line is uncommented, code compiles, as expected.

Playground Link: link

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label May 23, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 23, 2019
@RyanCavanaugh
Copy link
Member

Works as expected now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants