Typescript optimisation
I'm trying to optimise the generated types from the router, as I see that lots of types for context are being typed over and over instead of being made once and re-used, which influences total type to infer alot.
I managed to cut my total router dts from 1.5mb -> 840kb already (1.5mb being the tsc limit)
But I think we can do better
See attached image, the ctx object and transformers is present on every router
17 Replies
I know that in v11 there is work done for this aswell, so may be overlapping but was wondering if anyone else had tried to optimise the _config types before
Additionally _ctx_out could benefit from type reuse aswell, as I think if I could hard-type the output of my modified procedures where context changes, that it would speed up a lot
@Alex / KATT 🐱 I know you've also been compiling types lately, perhaps you've also encountered the 1.5mb limit like I have 🙈
So I managed to get the
ctx
to match my predefined type by doing explicitly typing the returns of all the createCtx functions☝️
So down to 754.55 KB 50% improvement 👀
Currently trying to hard-type procedure builders, however I'm a bit off on how it should be
have you upgraded to v11? we've removed the ctx and stuff on the resolver procedures
Is it ready to be used in prd tho :p
yes
Ait imma check out the resolved types
DTS src/server/api/root/index.d.mts 140.75 KB
omfg
lgtm 😄
Might no longer have to compile my types gahd damn
you probably want to do that still
do you still declarationMap?
CMD+clicking should work if you do
Hmm now I'm keen to set it up
Because I was so close to the limit of 1.5mb all the time
I put it off cuz I was gonne split the routers in seperate packages
to each have seperate compilation
But now I got a lot more headroom
bruhhh why did react query change isLoading to something else
i know, i tried to make the case that it was annoying
it's mostly search and replace tho
True true
Do you just compile the types cuz I esbuild the whole router and import that one xd