https://github.com/jasonkuhrt/experiment-ts-chain
https://github.com/jasonkuhrt/experiment-ts-chain
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jasonkuhrt/experiment-ts-chain
- Owner: jasonkuhrt
- Created: 2024-11-28T15:12:56.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-11-29T22:05:30.000Z (8 months ago)
- Last Synced: 2025-03-15T12:14:27.348Z (4 months ago)
- Language: TypeScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Experiment: TS Chain
## Problem Introduction
This experiment is to explore the optimal way to write a chaining API in TypeScript.
The problem with chaining APIs in TypeScript is that they are recursive which makes them prone to hitting TypeScript's internal limits, namely (to my knowledge) the three listed in this [article](https://medium.com/@hchan_nvim/into-the-chamber-of-secrets-break-through-the-limits-of-typescript-3532c6dd080):
1. Tail recursion count: the maximum number of recursive calls in a conditional type.
2. Type instantiation depth: the maximum depth when we instantiate a generic type alias.
3. Type instantiation count: the maximum number of type instantiations.## Experiment Setup
- Multiple approaches separated into their own modules
- Test modules co-located or otherwise using the top-level test suite module.## Findings
- No way found to never hit the limits.
- Different approaches yield different points at which limits are hit.
- Approach that yielded maximum chain size was "explicit recreate + type parameter".
- Can achieve extensible chaining API## References
1. https://github.com/microsoft/TypeScript/issues/30020
2. https://stackoverflow.com/questions/79232154/how-to-build-context-in-chaining-api-without-instantiation-limit?noredirect=1#comment139717622_79232154
3. https://www.reddit.com/r/typescript/comments/1c3r9gx/what_are_some_good_strategies_to_avoid_type/
4. https://stackoverflow.com/questions/70545982/why-am-i-getting-type-instantiation-is-excessively-deep-and-possibly-infinite