[Request for feedback] Nullable types, `null` and `undefined`
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
Solution: [Request for feedback] Nullable types, `null` and `undefined`
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: :)
Trust Score
4 verifications
- 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
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
@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
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep