It's probably duplicate but it's not easy to find so apologies if it is
interface A {
a: string // or `a: 'a'`
}
interface B {
a: number
}
declare var c:A|B
if (typeof c.a == 'string') { // or `if (c.a == 'a')`
c // <- Type: A|B, should be A ?
}
else {
c // <- Type: A|B, should be B ?
}
// where this seems ok:
declare var d:string|number // or `'a'|number`
if (typeof d == 'string') { // or `if (d == 'a')`
d // Type: string // Type: 'a'
}
else {
d // Type: number
}
It's probably duplicate but it's not easy to find so apologies if it is