class A {
readonly is_prop: boolean;
constructor(is_prop: boolean) {
this.is_prop = is_prop;
}
}
class B {
readonly my_prop: boolean;
constructor(my_prop: boolean) {
this.my_prop = my_prop;
}
}
type A1 = A & {is_prop: true};
type A2 = A & {is_prop: false};
type C = A1 | A2 | B;
const a: A = new A(true);
const b: A = new A(false);
const c: B = new B(true);
const e: A1 | null = a.is_prop ? a : null;
In the above example, why is the assignment for e giving error? Why is TS not inferring that is_prop will be true
A & {is_prop: true};equals to a type that has bothis_prop : booleanandis_prop: true. They aren't actually unified, which is what I believe you want which would betype A1 = Omit<A, 'is_prop'> & { is_prop:true};