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

Cache Declarations Directory #60905

Open
6 tasks done
Noriller opened this issue Jan 2, 2025 · 2 comments
Open
6 tasks done

Cache Declarations Directory #60905

Noriller opened this issue Jan 2, 2025 · 2 comments
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript

Comments

@Noriller
Copy link

Noriller commented Jan 2, 2025

πŸ” Search Terms

cache declarations cached tsserver tsc

βœ… Viability Checklist

⭐ Suggestion

A cache directory for declaration files that can be used both for normal type declaration and for tsserver.

This would be a shared folder to use for type definitions in development and possibly for build steps.

A separate folder could mean you have one service that could have it's own optimizations running in parallel or for some part of the project and emitting the declaration files, while the rest is worked normally or even tsserver rely only those declarations.

πŸ“ƒ Motivating Example

trpc/trpc#2448 (comment)

πŸ’» Use Cases

With tools that relies heavily on TS, some projects see inference times of seconds and have to rely on splitting code into a monorepo or some indirect compilation step and then depending on those types.

  1. What do you want to use this for?

Faster inference in large projects with tooling with complex, nested types.

  1. What shortcomings exist with current approaches?

Some relies on splitting code into a monorepo, others you need multiple tsconfigs so you can generate the types in one place and then reference them in the actual code, making indirections on the type system to keep the inference speed.

  1. What workarounds are you using in the meantime?

Have a parallel config to generate types and change a critical entrypoint to use the generated types instead of the normally inferred one.

@RyanCavanaugh
Copy link
Member

I don't understand what's being proposed here that isn't already implemented in project references.

What invalidates the cache?

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Jan 2, 2025
@Noriller
Copy link
Author

Noriller commented Jan 2, 2025

My current problem in one project is tsserver inference speed on routes of TRPC. Even without they changing, inference is slow.
From what I understand, tsserver needs to handle some dozens of files each time I call the aggregating API in the frontend, everytime. The problem happens not on build, but on inference time.

One of the possible solutions is moving to a monorepo, where I can build all the declaration files and tsserve can just use those without the need to make all the calculations every time.

However, if I could prebuild those declarations in another tool or even just have tsserver use a place as an explicit cache to be used. Then, the inference speed would be faster since the problem is it having to go through a lot of files that arent even changing.

Another, more hacky solution, is to use tsc with one config and emit declarations to one place and use tsc with another config as the config for the tsserver that points to use the compiled ones, but this generates other problems.

So, it's my understanding that if tsserver could save generated declarations, it would speed inference and those declarations don't need to be from tsserver, but could potentially be from tsc or other running in parallel and emitting declarations to a shared space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants