piotrwitek / typesafe-actions

Typesafe utilities for "action-creators" in Redux / Flux Architecture
https://codesandbox.io/s/github/piotrwitek/typesafe-actions/tree/master/codesandbox
MIT License
2.41k stars 99 forks source link

Optimize tsc start time in watch mode for big projects #236

Closed 11bit closed 2 years ago

11bit commented 4 years ago

Description

Hi!

I have a problem in a big project that uses typesafe-actions. tsc in watch mode starts many times slower than a standalone check.

After some googling and debugging I think I found the root cause of the slow down. Looks like tsc in watch mode generates temporary declaration (d.ts) files for incremental checks. And it turned out that generated typings for reducers are really big so that tsc spends a lot of time producing these temp files when starting.

The declaration files are big because of the recursive types that typescript doesn't handle well. For instance, this is what tsc produces for benchmarks/10-actions.ts from this repo - https://gist.github.com/11bit/ae4a19748c0ffaec44db4f2890e030d8. Looks like typescript tries to unfold them or something.

The workaround to optimize it is to expose these internal recursive types HandleActionChainApi and HandleTypeChainApi, so that tsc will be able to use them as is.

There is a discussion about a similar issue in typescript repo https://github.com/microsoft/TypeScript/issues/34119

Related issues:

Checklist

For bugfixes:

For new features:

piotrwitek commented 2 years ago

Thanks, it seems to make sense. Thanks for investigating this!