Skip to content

Bad error when using import() type within JSDoc tag @implements #58542

Open

Description

🔎 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 {}

Activity

  1. added
    Needs Investigation
    on Jun 17, 2024
  2. sandersn commented on Jun 17, 2024

    @sandersn
    Member

    @implements uses the same grammar as Typescript implements. This is an error in Typescript:

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

    However, the error is informative in typescript: "A class can only implement an identifier..." and not in Javascript. Javascript should give the same error.

    With the new @import tag, you should be able to /** @import { B } from 'a' */ instead of using @typedef.

  3. changed the title [-]Error when using `import()` type within JSDoc tag `@implements`[/-] on Jun 17, 2024
  4. added a commit that references this issue on Jun 17, 2024
    c89d96a
  5. added
    Fix Available
    on Jun 17, 2024
  6. added
    Bug
    and removed
    Needs Investigation
    on Jun 18, 2024
  7. jaydenseric commented on Sep 25, 2024

    @jaydenseric
    Author

    See also #49905 .

  8. added
    Domain: JSDoc
    on Oct 16, 2025
  9. removed
    Fix Available
    on Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugDomain: JSDoc

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions