-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Forbid non-promise types in @return on async functions #1345
Comments
@Daimona Curious what your workflow is? I'm guessing you've AFAIU, the /**
*
* @param {number} a - First number
* @param {number} b - Second number
* @returns {number} - Sum of a and b
*/
function add(a, b) {
const result = a + b;
return result.toString(); // Typed as `number` in JSDoc, but returns a `string`
}
const result = add(1, 2);
// ^? const result: number But if you've TS checking your And TS would also complain if the return type for an async function is not wrapped in So, this plugin is anyways not doing any type checking, it's just validating the presence of certain tags and description in JSDoc comments. Am I missing something?? Probably there's some other workflow that I'm not aware of, but I'm happy to learn. |
No, we aren't using TS. We only use vanilla JS and, well, eslint for linting.
No, I don't think you're missing anything. I am simply proposing that, as an enhancement (i.e., new functionality), the plugin should warn when |
Motivation
async
functions always return promises, and can never return anything else. Therefore, documenting an async function as@return {T}
is always wrong, unlessT
is (a subtype of) Promise.Current behavior
The existing rules do not flag those return tags as incorrect. This problem was also mentioned in #452 (comment).
Desired behavior
I would like to receive a warning if an async function is annotated as returning a non-promise. This could be part of an existing rule (presumably in the
require-return*
family) or a new rule. Either would work.Alternatives considered
If checking for non-promises in general is too complicated, it would be great to at least check native types for the time being. So warn for
@return {string}
,@return {void}
etc., but ignore@return {SomeCustomType}
.The text was updated successfully, but these errors were encountered: