vuejs / tsconfig

Base tsconfig for Vue 3 projects.
MIT License
307 stars 25 forks source link

Add "noEmit": true to compilerOptions #10

Closed richardsimko closed 1 year ago

richardsimko commented 1 year ago

The current config gives the following schema error:

Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set.

Setting "noEmit": true, in compilerOptions seems to resolve it, as Vite is doing the actual transpiling this seems to work fine.

dotoleeoak commented 1 year ago

Adding noEmit option disables importing SFC files, so I think adding the option is not the solution.

src/main.ts:10:17 - error TS2307: Cannot find module './App.vue' or its corresponding type declarations.

10 import App from './App.vue'
                   ~~~~~~~~~~~
haoqunjiang commented 1 year ago

Oops, I've only tested in command line with the --noEmit flag, so I didn't notice this issue. Thanks for reporting!

haoqunjiang commented 1 year ago

Adding noEmit option disables importing SFC files, so I think adding the option is not the solution.

I can't reproduce it locally. Could you open a new issue with a reproducible repository?

haoqunjiang commented 1 year ago

I did find a caveat of noEmit though: https://github.com/microsoft/TypeScript/issues/49844

If the root tsconfig.json is like this: https://github.com/vuejs/create-vue-templates/blob/fb8f80202ebcc33258742f602e6dd9399b417ead/typescript/tsconfig.json and the tsconfig.node.json is changed to extend from @vue/tsconfig/tsconfig.json, which includes noEmit, TypeScript would throw.

I have ideas to mitigate this issue, but they are too complicated and might not be worth the effort. 🤔 Maybe the allowImportingTsExtensions flag isn't that needed by default and I should revert it back…

haoqunjiang commented 1 year ago

To mitigate this issue, I can:

  1. Add more documentation in this repo
    • Explain that unless you are using SSR, you don't have to extend @vue/tsconfig in tsconfig.node.json;
    • If you do, consider disabling allowImportingTsExtensions in it.
  2. Update the create-vue tsconfig templates to always use files: [] in the root tsconfig
    • I'm a bit concerned that there may be issues with some tools depending on ts-node because it doesn't support solution-style tsconfigs; options have to be set in the root one. But we'll see.
  3. To further mitigate the issue, I can add one more extensible tsconfig file that enables emitDeclarationOnly, which could be recommended for Node + Vue usage. This can also be used to make Vitest type-checking faster and more comprehensible.

On the other hand, If I drop allowImportingTsExtensions by default in this package, I still plan to do 2 & 3, but the documentation in this repository could be much simpler. Users don't typically go here for documentation anyway.

After some thought and reading this issue, I think allowImportingTsExtensions only serves a very niche use case (at this moment):

So, I plan to drop allowImportingTsExtensions in the default configuration. I might add a section in the documentation on it later, if there are use cases beyond aesthetics.