Closed
Description
module A {
export const enum Brand {}
}
interface A {
brand: A.Brand;
a: string;
}
function isA(value: S): value is A {
return 'a' in <any> value;
}
module B {
export const enum Brand {}
}
interface B {
brand: B.Brand;
b: number;
}
function isB(value: S): value is B {
return 'b' in <any> value;
}
module C {
export const enum Brand {}
}
function isC(value: S): value is C {
return isA(value) && isB(value);
}
interface C {
brand: C.Brand;
a: string;
b: number;
}
type S = A | B | C;
function test(state: S) {
if (isA(state)) {
// works: state is A
} else if (isB(state)) {
// works: state is B
} else if (isC(state)) {
// works: state is C
} else {
// hey, state is A again! how come?
}
}