Кажется, что {a: never}
должно быть упрощено до never
. Это исправит мои проблемы ниже. Есть ли причина, по которой это невозможно?
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
// Couldn't N["value"] be simplified to never because an object of type N could never exist?
// And thus, couldn't N be simplified to never?
type AN = A | N
type ANtag = AN["tag"] // "A"
type ANvalue = AN["value"] // Expected: number, Actual: string | number
// AN has to be an A, an object of type N can't exist. 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 an A, an object of type B would never fit. So why can't NarrowToA["value"] be simplified to number?
Playground Link