Skip to content
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

@import JSDoc tag doesn't seem to account for resolution-mode import attribute in TS v5.5.2 #58955

Closed
acidoxee opened this issue Jun 21, 2024 · 1 comment Β· Fixed by #58966
Closed
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@acidoxee
Copy link

acidoxee commented Jun 21, 2024

πŸ”Ž Search Terms

"resolution-mode"

πŸ•— Version & Regression Information

I was unable to test this on prior versions because the @import tag is newly available on TS 5.5.2

⏯ Playground Link

No response

πŸ’» Code

// @filename: esm/esm.js
export type MyType = { foo: 'bar' }

// @filename: cjs/cjs.js
// This works:
/** @typedef {import('../esm/esm.js', { with: { 'resolution-mode': 'import' } }).MyType} MyType */

// This doesn't:
/** @import {MyType} from '../esm/esm.js' with { 'resolution-mode': 'import' } */

I couldn't create a TS playground because of this issue: #52666

πŸ™ Actual behavior

The @import usage in this context yields the following error:

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("../esm/esm.js")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mjs', or add the field "type": "module" to '/cjs/package.json'. ts(1479)

πŸ™‚ Expected behavior

The @import tag should account for import attributes like with { 'resolution-mode': 'import' } to enable cross CJS/ESM type imports.

Additional information about the issue

No response

@remcohaszing
Copy link

Here’s a practical example: https://github.com/mdx-js/mdx-analyzer/blob/bafdc57e39c75c7f494dd8b9ef7b4b1443725fea/packages/typescript-plugin/index.cjs#L8

I expected to be able to rewrite that line as:

/**
 * @import {Plugin} from 'unified' with {'resolution-mode': 'import'}
 */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
6 participants