total-typescript / tsconfig

The simplest way to set up your tsconfig.json
https://www.totaltypescript.com/tsconfig-cheat-sheet
874 stars 17 forks source link

Missing `"module": "preserve"` for bundler? #1

Closed chungweileong94 closed 5 months ago

chungweileong94 commented 5 months ago

Was it a mistake or there is a reason why we are not using "module": "preserve" for bundler?

References:

chungweileong94 commented 5 months ago

A bit of context, I personally use a lot of non-tsc toolings like tsx, bunchee & etc, so I use "module": "preserve" most of the time. I'm not sure if there are cases where we might not want to use "module": "preserve" for non-tsc or typescript version below v5.

mattpocock commented 5 months ago

100% a mistake, and a bizarre one. Thanks for the issue, fixed in 1.0.3.

kporten commented 5 months ago

When I use the following tsconfig.json, then VSCode provides .js extensions for all file imports (path auto-completion), even if I have only .ts files in my project:

{
  "extends": "@total-typescript/tsconfig/bundler/no-dom"
}
SCR-20240526-gtgb

I can get TypeScript imports back, when I change the tsconfig.json to:

{
  "extends": "@total-typescript/tsconfig/bundler/no-dom",
  "compilerOptions": {
    "module": "esnext",
    "moduleResolution": "bundler"
  }
}
SCR-20240526-gvyt
mattpocock commented 5 months ago

@kporten Could you provide a reproduction? Code looks fine to me.

kporten commented 5 months ago

Yes, here you can find the reproduction: https://github.com/kporten/reproduction-tsconfig-vscode/tree/main

In https://github.com/kporten/reproduction-tsconfig-vscode/blob/main/src/index.ts a note explains how to get the .js auto-completions instead of the .ts files.

mattpocock commented 5 months ago

@kporten Thanks, I also repeated your findings.

This seems like an upstream TypeScript issue to me. Appears that just having "module: preserve" isn't enough to fix these auto imports.

Raise something there and link this issue.