Skip to content

Intersection of non-null and null is not deduced to be never #33274

Closed
@Muon

Description

@Muon

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

No one assigned

    Labels

    BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions