-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
docs(decisions-0003): infer types for useLoaderData
from loader
type using generic
#3704
docs(decisions-0003): infer types for useLoaderData
from loader
type using generic
#3704
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic! Thanks for taking the time to write it up. A couple of things:
- Let's talk about actions
- Let's talk about deferred (Jacob is working on implementing support for that)
- I forgot what this one was, but I knew I had three 😅 I'll think of it later.
…ype using generic
0a58f74
to
0bf2d90
Compare
decisions/0003-infer-types-for-useloaderdata-from-loader-type-using-generic.md
Outdated
Show resolved
Hide resolved
decisions/0003-infer-types-for-useloaderdata-from-loader-type-using-generic.md
Outdated
Show resolved
Hide resolved
decisions/0003-infer-types-for-useloaderdata-from-loader-type-using-generic.md
Outdated
Show resolved
Hide resolved
decisions/0003-infer-types-for-useloaderdata-from-loader-type-using-generic.md
Outdated
Show resolved
Hide resolved
decisions/0003-infer-types-for-useloaderdata-from-loader-type-using-generic.md
Outdated
Show resolved
Hide resolved
include summary of current approach from v1.6.4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solid 👍 This is good to merge with my suggestions IMO.
.../0003-infer-types-for-useloaderdata-and-useactiondata-from-loader-and-action-via-generics.md
Show resolved
Hide resolved
|
||
export default function Route() { | ||
let dataGeneric = useLoaderData<MyLoaderData>() // <-- will be deprecated | ||
let dataCast = useLoaderData() as MyLoaderData // <- use this instead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work with our v2 plans, so let's go ahead and recommend what would be needed in that eventuality?
let dataCast = useLoaderData() as MyLoaderData // <- use this instead | |
let dataCast = useLoaderData() as any as MyLoaderData // <- use this instead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our v2 plans are to return unknown
in this case. You can type cast from unknown
to any type without TS getting mad. So useLoaderData() as MyLoaderData
will work for v2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh? That's great!
…ype using generic (remix-run#3704) * docs(decisions-0003): infer types for `useLoaderData` from `loader` type using generic * docs(decisions-0003): rewrite decision doc include summary of current approach from v1.6.4 * docs(decisions-0003): rename file to match title * docs(decisions-0003): fix typo * docs(decisions-0003): pr feedback
No description provided.