Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jaydenseric opened this issue May 15, 2024 · 2 comments Β· May be fixed by #58904
Open

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

jaydenseric opened this issue May 15, 2024 · 2 comments Β· May be fixed by #58904
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@jaydenseric
Copy link

πŸ”Ž 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 {}
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jun 17, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.6.0 milestone Jun 17, 2024
@sandersn
Copy link
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.

@sandersn sandersn changed the title Error when using import() type within JSDoc tag @implements Bad error when using import() type within JSDoc tag @implements Jun 17, 2024
sandersn added a commit to sandersn/TypeScript that referenced this issue Jun 17, 2024
Make @implements/@extends parse its expression with
`parseLeftHandSideExpressionOrHigher` instead of
`parsePropertyAccessEntityNameExpression`. This turns many more parse
errors into grammar errors, just like in TS. I kept
`parseExpressionWithTypeArgumentsForJSDoc` as a separate function in
order to keep parsing asterisks -- and `@implements` still only supports
a single interface, unlike TS which supports a list of them.

Fixes microsoft#58542
@sandersn sandersn linked a pull request Jun 17, 2024 that will close this issue
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jun 17, 2024
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Jun 18, 2024
@jaydenseric
Copy link
Author

See also #49905 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants