最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Correct JSDoc syntax for nullable return type? - Stack Overflow

programmeradmin4浏览0评论

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?

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?
Share Improve this question asked Nov 8, 2021 at 20:45 robertwerner_sfrobertwerner_sf 1,3134 gold badges25 silver badges44 bronze badges 1
  • 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
Add a ment  | 

1 Answer 1

Reset to default 16

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

@returns {?string}
@returns {string|null}
发布评论

评论列表(0)

  1. 暂无评论