robertwerner_sf
robertwerner_sf

Reputation: 1313

Correct JSDoc syntax for nullable return type?

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:

  1. @returns {?string}
  2. @returns [string]
  3. Something else?

Upvotes: 10

Views: 5845

Answers (1)

Majed Badawi
Majed Badawi

Reputation: 28424

You can do this in two ways, the first preferred:

@returns {?string}
@returns {string|null}

Upvotes: 16

Related Questions