FG
💻 Software🌐 Web & Full-StackMicrosoft

[Request for feedback] Nullable types, `null` and `undefined`

Freshabout 10 years ago
Mar 14, 20260 views
Confidence Score77%
77%

Problem

With the work on Nullable types in https://github.com/Microsoft/TypeScript/pull/7140, we would like to field some user input on the current design proposal. First some background: `null` and `undefined` JavaScript has two ways that developers use today to denote `uninitialized` or `no-value`. the two behave differently. where as null is completely left to user choice, there is no way of opting out of `undefined` , so: [code block] `a` will always implicitly has `undefined`, and so will the return type of `bar`. Nullability Given the JS semantics outlined above, what does a nullable type `T?` mean: 1. `T | null | undefined` 2. `T | undefined` 1. `T | null | undefined` It is rather subtle what `?` means in different contexts: [code block] 2. `T | undefined` This is more consistent, the `?` always means to `| undefined`; no confusion here. `T??` can be used to mean `T | undefined | null` or `T? | null`

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
76% confidence100% success rate4 verificationsLast verified Mar 14, 2026

Solution: [Request for feedback] Nullable types, `null` and `undefined`

Low Risk

My vote: Allowing `null` to be a valid nullable aka `T | null | undefined` Reasons: - `null` is used _quite a lot_ in node for `error` argument to callbacks. - `null` is in the name of _nullable_ - flow treats `null` and `undefined` the same : http://flowtype.org/docs/nullable-types.html @RyanCavanaugh looking back I did originally misread the question here :rose: :)

76

Trust Score

4 verifications

100% success
  1. 1

    My vote: Allowing `null` to be a valid nullable aka `T | null | undefined`

    My vote: Allowing `null` to be a valid nullable aka `T | null | undefined`

  2. 2

    Step 2

    - `null` is used _quite a lot_ in node for `error` argument to callbacks. - `null` is in the name of _nullable_ - flow treats `null` and `undefined` the same : http://flowtype.org/docs/nullable-types.html

  3. 3

    @RyanCavanaugh looking back I did originally misread the question here :rose: :)

    @RyanCavanaugh looking back I did originally misread the question here :rose: :)

Validation

Resolved in microsoft/TypeScript GitHub issue #7426. Community reactions: 5 upvotes.

Verification Summary

Worked: 4
Partial: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

typescriptcompilerdiscussion