Skip to content
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

Idea: Can declaration emit synthesize type aliases? #44045

Open
amcasey opened this issue May 11, 2021 · 4 comments
Open

Idea: Can declaration emit synthesize type aliases? #44045

amcasey opened this issue May 11, 2021 · 4 comments
Labels
Domain: Performance Reports of unusually slow behavior Experimentation Needed Someone needs to try this out to see what happens Suggestion An idea for TypeScript

Comments

@amcasey
Copy link
Member

amcasey commented May 11, 2021

Object types can be very large and in (e.g.) a react project that makes heavy use of type inference, it's not uncommon to have to refer to a type that is either not imported or is simply anonymous (e.g. a props type). When these appear in multiple places in a declaration file, they tend to expand it considerably. Perhaps we could just synthesize type aliases for them?

  • We'd have to be careful not to change the exported API shape
  • We could use a heuristic to skip the work for small types (e.g. < 20 characters)
  • Even if we didn't wait until the second use of a type to decide to extract it, we'd be adding ~4 tokens per type (type id = and id at the use site)
@amcasey amcasey added the Domain: Performance Reports of unusually slow behavior label May 11, 2021
@amcasey
Copy link
Member Author

amcasey commented May 11, 2021

With #44044, this is part of a larger discussion of how we could reduce the size of declaration files to make them faster to read and write (ideally, without sacrificing readability).

@weswigham
Copy link
Member

#30979 is along the lines of what I think we'd prefer to see

@amcasey
Copy link
Member Author

amcasey commented May 12, 2021

@weswigham What's the scope of those inline type aliases? Being able to use them across multiple declarations seems key to reducing declaration file size.

@RyanCavanaugh RyanCavanaugh added Experimentation Needed Someone needs to try this out to see what happens Suggestion An idea for TypeScript labels May 12, 2021
@weswigham
Copy link
Member

In that case, within a given type node, so you can serialize a recursive or self-referential type. (Which today usually expand till they hit a depth limiter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Performance Reports of unusually slow behavior Experimentation Needed Someone needs to try this out to see what happens Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants