microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

Home Page:https://www.typescriptlang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when using `import()` type within JSDoc tag `@implements`

jaydenseric opened this issue Β· comments

πŸ”Ž Search Terms

  • import
  • @implements
  • 2304

πŸ•— Version & Regression Information

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

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.5.0-beta&filetype=js#code/PQKhAIAEEsFsAcA2BTWyB2AXAzuA3nPAPYBOmAFAEQCGlAlAHQBCAvuCMAFADGi12uAIL4WQA

πŸ’» Code

/** @implements {import("a").B} */
class A {}

πŸ™ Actual behavior

Two TypeScript errors:

  1. Cannot find name 'import'. (2304)
  2. '}' expected. (2304)
Screenshot 2024-05-15 at 5 59 00β€―PM

πŸ™‚ Expected behavior

TypeScript should allow using import() types within the type of the JSDoc tag @implements.

Additional information about the issue

A workaround is to use a JSDoc @typedef to import the type under an alias, and then use that alias within the JSDoc tag @implements type, e.g:

/** @typedef {import("a").B} B */

/** @implements {B} */
class A {}