Skip to content

Add "noEmit": true to compilerOptions #10

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

Closed
richardsimko opened this issue Apr 22, 2023 · 5 comments
Closed

Add "noEmit": true to compilerOptions #10

richardsimko opened this issue Apr 22, 2023 · 5 comments

Comments

@richardsimko
Copy link

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
Copy link

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
Copy link
Member

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

@haoqunjiang
Copy link
Member

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
Copy link
Member

I did find a caveat of noEmit though: microsoft/TypeScript#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
Copy link
Member

haoqunjiang commented Apr 23, 2023

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):

  • People who want to use both tsc and Vite for transpilation in the same codebase won't need it.
  • People who only use Vite can continue to use the extension-less styles.
  • The only use case I can think of is that people who use esbuild and Vite on the same codebase while using tsc for type-checking and have already upgraded to TypeScript 5 and migrated their codebase to switch from .js to .ts, which, I believe would be very rare. Such a shared codebase isn't likely to need a Vue-specific configuration, either.

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.

haoqunjiang added a commit that referenced this issue Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants