How to make loader params type safe? #1133
-
Beta Was this translation helpful? Give feedback.
Answered by
tannerlinsley
Feb 2, 2024
Replies: 1 comment 3 replies
-
Type your constraints into your overview loader. Then fulfill them when you call it. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Extracting the loader from the route creates a 3-phase type-dependency chain: path/search/etc => loader => components (which use loader). So while theoretically possible (we tried in prior versions) it explodes the complexity and sometimes even the TS compiler. That said, it's a pretty standard pattern in all TS that if you extract a function from an inference scope, you'll need to type its signature to contain it's required constraints and return value. That's all that's happening here: