Closed
Description
TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)
Both 2.0.10 and 2.1.1
Problem
Flow Analyze don't work as expected when combining Intersection and Union syntax.
Example
B&A
B&C
works well as Code1.
A|C
works well as Code2.
B&A | B&C
compiled error as Code3.
test2.ts(18,21): error TS2339: Property 'a' does not exist on type '(B & A) | (B & C)'.
Property 'a' does not exist on type 'B & C'.
So should this be working as intended?
(B is to change type
to required, as Code1, this works.)
Def A,B,C
interface A {
type?: 'a';
a?: string;
}
interface B{
type: 'a' | 'c';
}
interface C{
type?: 'c';
c?: string;
}
Code 1: B&A
B&C
works well
//change type to required, works well
var ba: B&A;
if(ba.type == 'a'){
console.log(ba.a)
}
//change type to required, works well
var bc: B&C;
if(bc.type == 'c'){
console.log(bc.c)
}
Code 2: A|C
works well
//works well
var ac: A|C;
if(ac.type == 'a'){
console.log(ac.a)
}
Code 3: B&A | B&C
not works
//Compiled error
var abc: B&A | B&C;
if(abc.type == 'a'){
console.log(abc.a)
}
Metadata
Metadata
Assignees
Labels
No labels