Closed
Description
The intersection of non-null/undefined types with null
and undefined
is not deduced to be never
. Instead, things like string & null
persist unchanged. (This is with strict null checking.) This also applies to singleton types, so the type "a" & "b"
is not deduced to be never
.
TypeScript Version: 3.5.1
Search Terms: primitive null intersection never
Code
type T = string & null;
type U = T extends never ? number : never;
const a: U = 1;
Expected behavior: T is deduced to be never
, so U is number
, so it compiles.
Actual behavior: The code does not compile because T is not deduced to be never
and so U
is never
.
Playground Link: https://www.typescriptlang.org/play/#code/C4TwDgpgBAKlC8UDOwBOBLAdgcygMikwFcAbEgbgChRIoBVBWKCAD2AkwBMlCIA3CKigB+QkQC2AI0FQAXLwGoqAYwD2mFFACG8hogCM5IA