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

Auto import with .js extension instead of .ts with "allowImportingTsExtensions": true and package.json, imports fields #59553

Closed
theoludwig opened this issue Aug 7, 2024 · 0 comments Β· Fixed by #59564
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

@theoludwig
Copy link

πŸ”Ž Search Terms

"auto imports", "allowImportingTsExtensions", "package.json imports", ".js extension instead of .ts", "moduleResolution": "NodeNext"

πŸ•— Version & Regression Information

TypeScript v5.5.4

⏯ Playground Link

No response

πŸ’» Code

tsconfig.json:

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "allowImportingTsExtensions": true
  }
}

package.json:

{
  "type": "module",
  "imports": {
    "#*": "./src/*"
  }
}

src/lib/add.ts (not really important, the content of the file, path is more important):

export const add = (a: number, b: number): number => {
  return a   b
}

src/index.ts:

import { add } from "#lib/add.js" // WRONG AUTO IMPORT, using .js, instead of .ts
console.log(add(2, 3))

πŸ™ Actual behavior

Auto import with #lib/add.js"

πŸ™‚ Expected behavior

Auto import with #lib/add.ts" because I'm using the "allowImportingTsExtensions": true config option.

This is all the more relevant since the newly added CLI Flag --experimental-strip-types in Node.js, because it enforces imports to use the .ts extension.
Ref: https://nodejs.org/docs/latest/api/typescript.html

Additional information about the issue

Related issue: #52167

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
Development

Successfully merging a pull request may close this issue.

3 participants