Skip to content

The error for allowImportingTsExtensions does not reference rewriteRelativeImportExtensions #60397

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
fpapado opened this issue Nov 3, 2024 · 2 comments
Labels
Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@fpapado
Copy link

fpapado commented Nov 3, 2024

🔎 Search Terms

  • error TS5096
  • allowImportingTsExtensions
  • rewriteRelativeImportExtensions
  • tsconfig
  • diagnostics
  • intellisense

🕗 Version & Regression Information

  • This changed between versions N/A and 5.7.0-beta
  • This changed in commit or PR Rewrite relative import extensions with flag #59767
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries for allowImportingTsExtensions and rewriteRelativeImportExtensions
  • I was unable to test this on prior versions because it was only introduced in 5.7

⏯ Playground Link

No response

💻 Code

tsconfig.json with diagnostic error:

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

🙁 Actual behavior

When specifying allowImportingTsExtensions as above, I get an error, as intended:

tsconfig.json:5:35 - error TS5096: Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set.

However, if I add "rewriteRelativeImportExtensions": true to the same tsconfig, the error goes away, which is contrary to the error message.

The behavior seems correct, but the error message seems incomplete or inconsistent.


At the same time, intellisense for allowImportingTsExtensions in VSCode reports:

Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set.

This is only mentioned as a requirement in intellisense, but not in the error message.

🙂 Expected behavior

I would expect the message to reference rewriteRelativeImportExtensions as one of the conditions that allow for allowImportingTsExtensions.

I am not sure whether --moduleResolution bundler is required, but at least unifying the intellisense and diagnostic would be good.

The combination of factors seems to be "noEmit or emitDeclarationOnly or rewriteRelativeImportExtensions", but I am not sure what the exact new diagnostic message should be 😅

(I don't mean to be nitpicky! I tend to learn best from intellisense and the diagnostics errors, so I was on the lookout for them when trying out the 5.7.0-beta and rewriteRelativeImportExtensions 😌)

Additional information about the issue

No response

@fpapado fpapado changed the title The warning for allowImportingTsExtensions is inconsistent with rewriteRelativeImportExtensions The error for allowImportingTsExtensions does not reference rewriteRelativeImportExtensions Nov 3, 2024
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Help Wanted You can do this labels Nov 4, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Nov 4, 2024
@KurtGokhan
Copy link

KurtGokhan commented Dec 8, 2024

I couldn't find a working configuration for using rewriteRelativeImportExtensions and allowImportingTsExtensions together. I want tsc to emit, and rewrite .ts to .js. But the LSP errors on me when I add allowImportingTsExtensions: true to my tsconfig. Also rewriteRelativeImportExtensions isn't allowed in tsconfig, which doesn't make sense.

Edit: My bad. rewriteRelativeImportExtensions is allowed in tsconfig. VSCode was using 5.6 and it confused me.

@zanminkian
Copy link

zanminkian commented Jan 7, 2025

Addition: rewriteRelativeImportExtensions can exist in tsconfig.json, but official document does not mention it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants