-
Notifications
You must be signed in to change notification settings - Fork 12.8k
[Feature Request] Add types to specify nullable/maybe values #49530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
See #41901 (comment) for why this likely won’t be implemented. |
What you referenced is totally different thing. I'm not requesting for
The thing I'd like to see are simple type aliases which don't add anything new to TypeScript syntax. It would be the same thing as |
See #39522 (comment):
|
It’s not exactly the same, but the same concerns apply, namely that people will argue endlessly over whether |
Yes, I'm aware of that, hence I've proposed two separated type aliases and optional third which would be a compound. Anyway sure, it's more clear now. Also @MartinJohns's addition expleinaed some cases so I understand you guys had endless debates about that and decided you'll go this way. I'll close that as not planned. Thanks for answers! |
Uh oh!
There was an error while loading. Please reload this page.
Suggestion
🔍 Search Terms
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
I'd like to have type aliases that specify whether type is nullable or probably undefined. Something like:
Just in case - I wouldn't compose those two unless it's a third type (
MaybeNullable
?). Lot of projects try to omitnull
and useundefined
instead. Having type which says something can be both would be useless in such projects.📃 Motivating Example
TypeScript has
NonNullable
type which is mostly useless withstrictNullChecks
option enabled. On the other hand there are no types to specify nullable or probably undefined type aliases. While we can just typetype | null
ortype | undefined
, it's more readable, faster and cleaner to do that with type aliases.💻 Use Cases
Instead of:
We can have more readable alternatives:
The text was updated successfully, but these errors were encountered: