Skip to content
Discussion options

You must be logged in to vote

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:

const Route = createRoute({
  ...
  loader: ({ params }) => fetchPostById(params.postId)
})

function fetchPostById(postId: string): Post {
  ...
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tykhan
Comment options

@tykhan
Comment options

@tannerlinsley
Comment options

Answer selected by tykhan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants