Skip to content

How to write the correct type for useLoaderData()? (Typescript) #9792

Closed Answered by Vanilla2
blatoo asked this question in Q&A
Discussion options

You must be logged in to vote

Just stumbled across the same problem, I temporarily found the next workaround.

const data = useLoaderData() as Question[];

Where I definitely know that my loader returns an array of type Questions (which is defined by me).

I don't really like this work-around, as it defeats the purpose of typescript and it might introduce bugs.

Replies: 12 comments 38 replies

Comment options

You must be logged in to vote
14 replies
@clarencetinator7
Comment options

@NoamAnisfeld
Comment options

@fredericoo
Comment options

@NoamAnisfeld
Comment options

@soullivaneuh
Comment options

Answer selected by MichaelDeBoey
Comment options

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

@soullivaneuh
Comment options

@soullivaneuh
Comment options

Comment options

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

@MattyBalaam
Comment options

@fredericoo
Comment options

Comment options

You must be logged in to vote
6 replies
@fredericoo
Comment options

@eric-horodyski
Comment options

@fredericoo
Comment options

@eric-horodyski
Comment options

@LucasKuhn
Comment options

Comment options

You must be logged in to vote
1 reply
@fredericoo
Comment options

Comment options

You must be logged in to vote
1 reply
@rafaelbiten
Comment options

Comment options

You must be logged in to vote
1 reply
@fredericoo
Comment options

Comment options

You must be logged in to vote
2 replies
@fredericoo
Comment options

@eric-horodyski
Comment options

Comment options

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

@QuentinGibson
Comment options

@fredericoo
Comment options

Comment options

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

@fredericoo
Comment options

@LucasKuhn
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@kiliman
Comment options

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