Laurens Lavaert
Laurens Lavaert5mo ago

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
No description
17 Replies
Laurens Lavaert
Laurens Lavaert5mo ago
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
Laurens Lavaert
Laurens Lavaert5mo ago
☝️
No description
Laurens Lavaert
Laurens Lavaert5mo ago
So down to 754.55 KB 50% improvement 👀
Laurens Lavaert
Laurens Lavaert5mo ago
Currently trying to hard-type procedure builders, however I'm a bit off on how it should be
No description
Alex / KATT 🐱
have you upgraded to v11? we've removed the ctx and stuff on the resolver procedures
Laurens Lavaert
Laurens Lavaert5mo ago
Is it ready to be used in prd tho :p
Alex / KATT 🐱
yes
Laurens Lavaert
Laurens Lavaert5mo ago
Ait imma check out the resolved types
Laurens Lavaert
Laurens Lavaert5mo ago
DTS src/server/api/root/index.d.mts 140.75 KB omfg
Alex / KATT 🐱
lgtm 😄
Laurens Lavaert
Laurens Lavaert5mo ago
Might no longer have to compile my types gahd damn
Alex / KATT 🐱
you probably want to do that still do you still declarationMap? CMD+clicking should work if you do
Laurens Lavaert
Laurens Lavaert5mo ago
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
Alex / KATT 🐱
i know, i tried to make the case that it was annoying it's mostly search and replace tho
Laurens Lavaert
Laurens Lavaert5mo ago
True true Do you just compile the types cuz I esbuild the whole router and import that one xd