-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Tree-shaking d.ts files #47137
Comments
This isn't possible to do in a way that preserves correctness. Any source file might have a |
@RyanCavanaugh can you help me to understand this, as I am not quite sure why can't do this in a correct way. |
How does it know which declarations are required? |
This is how
when I say
as we still know we only interested in S3 import, it is safe to totally ignore everything else. If the problem is, that S3 namespace augmentation could happen |
Also thinking about to introduce some kind of 'pure' type exports where tsc can mark namespaces where it is safe to assume that no other d.ts in that module will modify anything else. |
Consider this example: // a.ts
import { foo } from "bar";
// bar's entry point, wherever that is
export import foo from "./stuff"
(hundreds of thousands of more lines)
export import baz from "./types";
// ./stuff
export const a: SOME_TYPE;
// ./types
declare global {
interface SOME_TYPE { }
}
export baz: string; |
I think you miss the point. When editing
Consuming that When creating |
You said
Did you mean emit only the "required" .d.ts file? |
Absolutely no. Or depends on the implementation of this feature, as if it requires slightly modified emitted d.ts, then yes, the corresponding @types/module has to be recompiled. Then my module can see that it is safe or not to import only the required type from Here is some comparison, initial build times:
This is not much, but the memory usage already a lot higher, but not compare the incremental build performance during watch:
This is now insane. Check the memory usage, the nodes count, and the build time. Nonsense. |
It seems like the only place where this could be done (i.e. places where there are "islands" of no out-reaching dependencies) is where the modules already have the structure in place such that you could deep-import e.g. In the general case, this is going to mean that features like auto-import fail to offer up symbols that people expect to find. It's also very unclear how libraries would figure out that they are structured in a way (no globals, no augmentations, no top-level module decls, etc) that would make this a safe optimization. You can actually achieve this behavior today by specifying |
Yes, I absolutely don't understand this difference with incremental builds, as About figuring out if libraries structured in a good way I thought there is already an And saying it is related to Nodes of Definitions: 7 This can not be normal. As I said, these are add up. |
@steveetm |
This issue has been marked as "Declined" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Tree-shaking with d.ts files
Importing part of modules using the root index.d.ts file.
π Search Terms
d.ts tree-shaking type import destructuring
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Parse only the required d.ts file.
π» Use Cases
We have several modules which uses larger modules with extensive typings, e.g
aws-sdk
.When we import only S3
aws-sdk/index.d.ts
got parsed. These bigger modules can add up, increasing required resources for compilation with increased compile time.If I import S3 directly, then the matching d.ts file parsed only:
I did some experiment changing few of these imports and examined a few tsc traces, parse part went down for 10 seconds to 4, obviously the parsed declaration number went down accordingly.
Tried to look for various config combinations, but found nothing about this.
The text was updated successfully, but these errors were encountered: