'Why type intersections results in never type?
Could you please explain why the following type expression results in never type? And why the second expression evaluates to "{ d: false, e: never }"?
// 1、
// never
type DataTypeNever = {
d: true;
e: number;
} & {
d: false;
e: number;
}
let data: DataTypeNever = (() => {
throw new Error
})()
// 2、
// { d: false, e: never }
type DataType = {
d: false;
e: number;
} & {
d: false;
e: string;
}
let data: DataType = {
d: false,
e: (() => {
throw new Error
})()
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
