-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useLoaderData<typeof loader>() returns incorrect type #4529
Comments
Hey @andrecasal, I would recommend upgrading your Remix packages to at least 1.6.5, where we enhanced type inference from Closing this as it's already fixed. |
Awesome, thanks! |
I just realized the version I'm using I mistakenly looked at the
|
@andrecasal make sure you use the same version for all packages, or you might have some inconsistent behaviors. As for the loader, you need to hint its parameter with LoaderArgs for type inference to work: export async function loader(args: LoaderArgs) {
return json(data);
} or export async function loader({request}: LoaderArgs) {
// do your thing with request
return json(data);
} |
Please try the function form as mentioned in the release note. export async function loader({request}: LoaderArgs) {
return json({ events: await getEvents() });
} |
@machour Using both function or arrow function should work here. I think the problem is |
@MichaelDeBoey you're right model Event {
id Int @id @default(autoincrement())
title String @unique
type String
image String
start DateTime
end DateTime
description String
location Location @relation(fields: [locationId], references: [id])
locationId Int
streamLink String?
registrationLink String
price Int
}
model Location {
id Int @id @default(autoincrement())
name String @unique
address String
lat Float
lng Float
Event Event[]
} The Prisma client returns all DateTime as native Date objects, which breaks the type checking when communicating values from the backend to the frontend. I changed Thank you for your help guys! |
Out of curiosity, how would you deal with DateTimes In Prisma? It's saved as a Do you avoid |
Checkout |
Excellent work Kiliman, thank you 😄✌️ |
Is adopting typedjson in Remix's roadmap and making this transparent for the developer? |
@andrecasal I don't think it's the case. |
Yeah I don't think every feature must be included in Remix core. I like that the Remix API gives you nice building blocks that you can put together as needed. |
What version of Remix are you using?
1.7.5
Steps to Reproduce
In the following code, the events variable has the wrong type:
yielding an error on the
map()
function:Steps to reproduce
events.tsx
routeI'll create a test once this bug's confirmed.
Expected Behavior
I'd expect useLoaderData() to give me the type:
or on the example with a hardcoded array:
Actual Behavior
useLoaderData<typeof loader>()
type isSerializeObject<UndefinedToOptional<Event>>[]
The text was updated successfully, but these errors were encountered: