Skip to content

NonNullable<null> is null without strict null checks #50519

Description

@dummdidumm

Bug Report

NonNullable<null> was never in all cases previously, since 4.8 it's null when strictNullChecks: false. From reading the PR that changed the implementation of NonNullable I can't really tell if this is now expected or an oversight. If it's expected, maybe the blog post could be updated because I think this is a significant difference in behavior.

🔎 Search Terms

NonNullable never null

🕗 Version & Regression Information

  • This changed between versions 4.7 and 4.8

⏯ Playground Link

Playground link with relevant code (same behavior for 4.7, but the implementation of NonNullable was different there)

💻 Code

type NonNullableNew<T> = T & {};
type NonNullableOld<T> = T extends null | undefined ? never : T;

type IsNullWithoutStrictNullChecks = NonNullableNew<null>;
type IsAlwaysNever = NonNullableOld<null>;

🙁 Actual behavior

NonNullable<null> returns null with strictNullChecks: false

🙂 Expected behavior

NonNullable<null> always returns never

Metadata

Metadata

Assignees

Labels

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

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions