-
Notifications
You must be signed in to change notification settings - Fork 12.8k
null is not assignable to void when strictNullChecks are enabled #16075
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
do not use |
I don't it's more like if I want to represent
Interesting! Where can I learn about how Never the less, I wanted to point out that behavior and linked documentation seems to be inconsistent. If implemented behavior makes more sense that documented behavior that's fine, but in that case maybe docs should be get updated to avoid misleading newcomers like me ;) |
Not sure why the docs say that (maybe there was some confusion with function return types). Should edit to fix. |
I find this issue crops up in this (highly contrived) situation (nodejs) - in real world situations there are sometimes promise functions that don't error but don't do anything in certain circumstances and so a direct resolve makes sense. Is there a way to do this? function someFunc():Promise<void> {
// Can't do this because resolve expects a value
return Promise.resolve();
// Can't do either of these or you get the error mentioned:
return Promise.resolve(null);
return Promise.resolve(undefined);
} |
@RyanCavanaugh I would do a PR to fix this. Can't find where in the repo I should do this though. Edit: Done, PR open: microsoft/TypeScript-Handbook#1053 Similar issue here: #11758, would probably also close that issue. |
Ah, I guess the docs are in the TypeScript-Handbook repo. I suppose in this file: |
According to the documentation Null and Undefined are assignable to
void
.Bun in my experience only
undefined
is actually assignable tovoid
:TypeScript Version: 2.3
Code
Expected behavior:
I would expect
null
to be assignable tovoid
. It makes forvoid
to be just a uniontype void = null | undefined
otherwise it's just an alias forundefined
.Actual behavior:
Only
undefined
is assignable tovoid
.The text was updated successfully, but these errors were encountered: