With Javascript function JSDocs, I've seen two different syntaxes for documenting the return values that can be nullable.
Let's say we have this function:
const getTitle = () => { // Can return string or null };
For this, which of the following JSDocs is correct:
- @returns {?string}
- @returns [string]
- Something else?
With Javascript function JSDocs, I've seen two different syntaxes for documenting the return values that can be nullable.
Let's say we have this function:
const getTitle = () => { // Can return string or null };
For this, which of the following JSDocs is correct:
- @returns {?string}
- @returns [string]
- Something else?
- 1 I wrote this cheat sheet to help me with this. Sharing in case it's useful. – custommander Commented Nov 9, 2021 at 8:33
1 Answer
Reset to default 16You can do this in two ways, the first preferred:
@returns {?string}
@returns {string|null}