Microsoft/TypeScript

JSDoc `@callback` tag types are only checked if referenced by code

Open

#47,608 建立於 2022年1月26日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: JSDocHelp Wanted

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

Bug Report

🔎 Search Terms

@callback jsdoc "no error"

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about @callback

⏯ Playground Link

Playground link with relevant code

💻 Code

// @ts-check

/**
 * @callback UnreferencedCb
 * Does not report an error on "badtype".
 * @returns {badtype}
 */

/**
 * @callback ReferencedCb
 * Reports an error on "badtype", but only if ReferencedCb is referenced by actual code.
 * @returns {badtype} abc
 */

/**
 * @typedef {badtype} UnreferencedType
 * Properly reports an error on "badtype".
 */

/** @type {ReferencedCb} Without this reference, the badtype in ReferencedCb is ignored. */
const foo = () => 'abc';

🙁 Actual behavior

The badtype in the definition UnreferencedCb is not marked as an unknown name, but it is one. Typing some JS code with UnreferencedCb causes TS to behave correctly and be marked as an unknown name.

The other badtypes are correctly marked as unknown names (Cannot find name 'badtype'.(2304)).

🙂 Expected behavior

All occurrences of badtype should be marked as syntax errors with Cannot find name 'badtype'.(2304), since that type is not defined.

The @callback JSDocs should be checked when // @ts-check is enabled, regardless of whether they are actually referenced by JS code in the same file.

貢獻者指南