-
Notifications
You must be signed in to change notification settings - Fork 401
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
aviod compilation with swc + type-checking when there are type errors #2646
Comments
What's the reason for using SWC instead of tsc if you want to wait for type-checking to complete? |
We switched from the default compiler to SWC because of speed. With the default compiler, it got to a point where it took ~2 minutes (on fast machines) to compile the project. With SWC it takes ~2 seconds. On the same project, So (we assumed) something else beyond tsc is slowing down the default compiler and switching to SWC seemed the better approach for our use case, rather than investigating alternative ways to speed things up. But, after a few weeks, we noticed we lost the functionality of type checking being a safeguard during compilation. |
@aberonni We are also using SWC with type checking enabled, and we noticed that live-reload (nest start --watch) happens twice when type checking is enabled. I believe this might be caused by the autogenerated metadata.ts file when type checking is enabled with SWC. How did you guys work around this problem? |
I'm not sure we have that metadata.ts file being autogenerated, but tbh I haven't looked into our setup in a while. AFAIK we don't have the double compilation issue. |
@aberonni Hmm that's interesting. The Nest.js will generate metadata file automatically when type check is enabled with SWC: https://docs.nestjs.com/recipes/swc#cli-plugins-swc |
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
When using SWC with NestJS, there is a handy type checking functionality. When there is a type error, you see a log in the console, but the project still compiles successfully.
I originally opened this as a bug, but I have been told this was expected behaviour: nestjs/nest#13760 so I thought it would be a good idea to report this as a feature request instead. You can see a full log example in that issue.
Describe the solution you'd like
When the type check flag is used and there is a type error, the SWC compiler does not compile the project nor show the "Application successfully started" message.
(AFAIK this would be the same behaviour as the compiler without SWC)
This should probably be configured through a new flag/configuration variable to avoid breaking changes for people already using the type check flag.
Teachability, documentation, adoption, migration strategy
For example:
Type checking
SWC does not perform any type checking itself (as opposed to the default TypeScript compiler), so to turn it on, you need to use the
--type-check
flag:$ nest start -b swc --type-check
If you wish for compilation to fail when using type checking, then you can use the
--type-check-fail
flag$ nest start -b swc --type-check-fail
What is the motivation / use case for changing the behavior?
This was the behaviour when using the non-SWC compiler. We got used to relying on the NestJS compilation output log to determine whether we were introducing TS errors and to safeguard us against them.
The text was updated successfully, but these errors were encountered: