-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Unhelpful "Did you forget to include 'void' in your type argument to 'Promise'" in JS file #46570
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
Note for repro: this requires setting: "strict": true,
"checkJs": true In your jsconfig |
Minimal repo: new Promise(resolve => resolve()); Can be worked around with a type annotation: /**
* @type {Promise<void>}
*/
(new Promise(resolve => resolve())); |
Moving upstream. The current behavior looks expected for strict mode but I agree the experience is not great. Looks like there is already a quick fix for it though: Some other ideas:
|
Hm interesting, I didn't notice the quick fix, and I see I did have: "js/ts.implicitProjectConfig.checkJs": true,
"js/ts.implicitProjectConfig.strictNullChecks": true, globally configured. So I guess this is pretty reasonable, I'd be fine to just close it out. |
@DanielRosenwasser @rbuckton what should this message even say in JS? We should at least ditch the “did you forget” language, since what we’re asking JS users to do is pretty weird. |
Maybe
|
+JSDoc?
|
Hi all, I'm new here and trying to take this one on. Would appreciate some feedback on the pr (especially around localization) |
@osaimola localization happens automatically after the fact. All you have to do is write the English text in |
@DanielRosenwasser @andrewbranch This confused me:
a new Promise() without a handler or anything in it that calls resolves produces already never and that is correct has the analyzer can not track that it gets resolved some where. it does 100% not return void. new Promise(res=res()) produces void. and even calling res with (undefined) is void. at last out of engine view it translates to the same byte code. |
@andrewbranch Is this issue still open? In case I would like to contribute :) |
Ok I'll try during this weekend, thanks! :) |
this error message is very annoying... don't think a jsdoc should even be necessary (as the resolver argument is optional) |
@jimmywarting The argument is not optional (in a strong-typing sense) for anything other than a |
@fatcerberus it is missing in general a lot of inference by design but it is the best that works at present i am not sure about the state of flow is it solving some issues does it still exist? |
I think it's should be optional... I seen many ppl using pattern like the following where a return value isn't necessary function sleep (time) {
return new Promise(resolve => setTimeout(() => resolve(), time))
}
// or
sleep = time => new Promise(resolve => setTimeout(resolve, time))
worth mentioning that i do not write stuff with typescript syntax. i only have |
Right, that’s what this issue aims to solve, so you can write that without complaint. But in general, the argument is not (and should not be) optional if the promise has a type other than I don’t think anybody is arguing with you that your examples should work as written; the fact they don’t is due to a design limitation of generic inference that needs to be solved. Making the resolver argument optional would of course fix your examples, but in the process it would compromise type safety for TS programs (or even jsdoc-based ones with |
TS Template added by @mjbvz
TypeScript Version: 4.5.0-dev.20211028
Search Terms
See #46570 (comment) for more minimal repro
In minimal-hello-world extension sample, using this code:
I see this error:

This isn't really something we should be warning about in JS.
The text was updated successfully, but these errors were encountered: