-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
TypeScript compiler stucks with --incremental flag #31258
Comments
This seems to be stuck in declaration emit. |
One of the declaration files we produce is 209163 lines long. (specifically the output for type repeated = {
type: TConfigs[number]["type"];
str1: string;
str2: string;
} and the rest are spent nesting a bunch of Our canonical response in cases like these, thus far, is to recommend adding a type annotation to the offending declaration, so we can avoid the generation process entirely. Now, while I said that I don't think all of the complexity in the printback can be avoided, I think #30979 or something like it (specifically the |
TL;DR: There's no simple "fix" here because nothing is going "wrong" - our declaration emit just just less expressive than the input code, and it shows in the complexity of the output. At least the work around is pretty easy to do: add a type annotation on your function returns (which, given that a builder pattern is in use, probably isn't what anyone wants to hear, as it kills an advantage to the strongly typed builder, but it's what we have right now). |
This. I've been burned by it too many times that I've basically requested a lint rule be written for it, When it comes to generic functions/methods, always err on the side of caution and explicitly annotate the return type. Even if the expected emit is "obvious" (to a human). If you're composing them, this rule goes triple. You'll save yourself a lot of declaration emit headaches. Without a lint rule, you can just... Forget to annotate. I'm pretty rigorous about it, usually. But the one time I forgot, my build time became insane. One time I forgot to explicitly annotate, it ended up emitting weird stuff, I'd say I have quite a lot of experience with generic functions/methods, composing/chaining them, and fluent/functional APIs. It's not unusual for me to have 300 LoC on one file and only 36 lines are executable JS. The other 264 lines are mostly type declarations (interfaces, classes, type aliases) and comments. More often than not, the comments are maybe 50 LoC or less This is one of the more "tame" files I've written recently, Mostly comments, a bunch of type aliases. And, finally, executable code at the very bottom. That "util" function is later used by a class that implements a builder pattern in a different project,
200k lines is better than being OOM during emit. At least the user can see output and go "that's strange" without having to attach a debugger! |
Thanks for the investigation. However, the reason we use this library is that we don't want to write unnecessary type definitions explicitly. Since it works well without |
It's probably also worth noting that your config had both incremental an |
TypeScript Version: 3.4.5
Search Terms:
stuck, slow, incremental
Code
https://github.com/ms-qinyang/typescript-stuck-incremental
run
npm run buildIncremental
Expected behavior:
Compiler should be finished in a short time
Actual behavior:
Compiler takes more than 1 minute to finish. Since the real project has many files, the compiler won't be finished in an acceptable time. This breaks typecheck in
create-react-app
after 2.1.8Related Issues:
The text was updated successfully, but these errors were encountered: