Is there a reason the code {a: never}
cannot be simplified to just never
? I believe this change would resolve the issues mentioned below.
type A = {tag: 'A', value: number}
type B = {tag: 'B', value: boolean}
type N = {tag: never, value: string}
type Ntag = N["tag"] // never
type Nvalue = N["value"] // string
// Could N["value"] potentially be simplified to never since an object of type N should not exist?
// Therefore, why can't N simply be reduced to never?
type AN = A | N
type ANtag = AN["tag"] // "A"
type ANvalue = AN["value"] // Expected: number, Actual: string | number
// AN must be A as an object of type N is impossible. So, why can't AN["value"] be simplified to number?
type AB = A | B
type NarrowToA = AB & {tag: 'A'} // Expected A, Actual: (A & {tag: "A"}) | (B & {tag: "A"})
type NarrowToATag = NarrowToA["tag"] // A
type NarrowToAValue = NarrowToA["value"] // Expected number, Actual number | boolean
// Again, NarrowToA has to be A as an object of type B wouldn't align. Why can't NarrowToA["value"] be simplified to number?