Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
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
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Activity
jack-williams commentedon Sep 6, 2019
Fixed by #31838.
Muon commentedon Sep 6, 2019
Ah, thank you. Reading through that PR, it seems that pre-3.6, the reduction can be forced by taking a union, so e.g.
(string & null) | neverreduces tonever.