-
-
Notifications
You must be signed in to change notification settings - Fork 169
Closed
Labels
Description
Expected behavior
The following function should not have any jsdoc errors:
/**
* @param x A useful param.
* @returns A useful string.
*/
function foo( x: boolean ): string | undefined {
if ( x ) {
return 'bar';
}
}It's typescript code, which means that types aren't encoded in the jsdoc @returns tag. You can solve this by putting @returns {string|undefined}, which isn't valuable (though it would be valuable for JS functions), or by adding return to the very end, which also isn't valuable.
Is this a bug or expected behavior? If it is expected behavior, I think the default rule shouldn't require empty return tags for this scenario!
While this can also happen for JS code, I think it's somewhat useful, in that it forces you to put the correct type beside @returns if the function doesn't always return something. But that's already covered by typescript.
Actual behavior
This error occurs:
JSDoc @returns declaration present but return expression not available in function
ESLint Config
'jsdoc/require-returns-check': 'error'ESLint sample
See above
Environment
- Node version: happens in both 16 and 18
- ESLint version: 8.14.0
eslint-plugin-jsdocversion: 39.6.6 (latest)