1. 6
    Integrate TypeScript Into a Remix Loader Function
    2m 12s

Integrate TypeScript Into a Remix Loader Function

InstructorKent C. Dodds

Share this video with your friends

Send Tweet

We can take advantage of TypeScript by setting our loader function to the LoaderFunction type from @remix-run/node

Then we can ensure that our loader is returning the type that we want by creating a custom type called LoaderData with a property of posts.

We’ll also do a cool trick where we get the awaited return type of our getPosts async function. This is done like this posts: Awaited<ReturnType<typeof getPosts>>

lolgrifon
~ a year ago

Where is the video for this lesson?

Patrik Affentranger
~ a year ago

Feels odd to have to type cast useLoaderData as LoaderData when in v1 it was possible to do useLoaderData<typeof loader>()? Will this be changed again in the future to not have to cast types and infer them instead?