Repository: TypeScript
Issue: JSDoc `@callback` tag types are only checked if referenced by code
Labels: Bug,Help Wanted,Domain: JSDoc

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms

<!--
  What search terms did you use when trying to find an existing bug report?
  List them here so people in the future can find this one more easily.
-->
`@callback` jsdoc "no error"

### 🕗 Version & Regression Information

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to
  https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies:
-->
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about `@callback`

### ⏯ Playground Link

<!--
  A link to a TypeScript Playground "Share" link which shows this behavior

  The TypeScript Workbench can be used for more complex setups, try
  https://www.typescriptlang.org/dev/bug-workbench/

  As a last resort, you can link to a repo, but these will be slower for us to investigate.
-->
[Playground link with relevant code](https://www.typescriptlang.org/play?filetype=js#code/PTAEAEBcGcFoGMAWBTeBrAsAKG8AVHtqHhPAIYA2FARmeqAKoB2ATsgGbJtPzIAmAYWpESAEQD2yaKCbjIoNgAdxLeWSaguLFaHEaARLT6QAnouT6AdCIhtIAVxZNpAbyOnzAXxHBsuAjbg5FS09ABKHFzIPPxCNhHKqtLqmizaLLoG7mYWADSg1PbyehQmoACW7KARnNy8gtQV0my10fUFZXQOlKDw4nzI1ljEtsgOTq7ZXqBk1PA+flj4hMMkUDkDVW5kxjmejKyRdfwAKjk2AAra5iylCsiJMDMaWjp6oIY7HhZDxL44SwIEG+oBcNSiMQa+wA6uVIIhxEVQPDys0jm1kPl4cgCl8chUNODjg0mhUAOayNh8Sx-bB9ZzydjicSgAC8oAAFABKNkAPlAAHJZvABQBubBAA)

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```ts
// @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.
<!-- What happened, and why it was wrong -->

The other `badtype`s 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.
<!-- What you expected to happen instead, and why -->

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.