Skip to content
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

Type error when inferring the type of ReadonlyArrays returned from useLoaderData #3762

Closed
JNaftali opened this issue Jul 16, 2022 · 3 comments · Fixed by #3774
Closed

Type error when inferring the type of ReadonlyArrays returned from useLoaderData #3762

JNaftali opened this issue Jul 16, 2022 · 3 comments · Fixed by #3774

Comments

@JNaftali
Copy link
Contributor

What version of Remix are you using?

1.6.5

Steps to Reproduce

I've reproduced it as a minimal fork of the stackblitz remix starter - https://stackblitz.com/edit/node-d35hmw

  1. return a ReadonlyArray from a loader
  2. attempt to access that array using useLoaderData<typeof loader>()
  3. observe the type error when attempting to use array methods

Expected Behavior

The array should be typed correctly and methods such as array.map should be allowed. Either the array should come through typed as Array or as ReadonlyArray

Actual Behavior

the object is typed as a bare object with numeric properties and lacking all array methods.

@JNaftali
Copy link
Contributor Author

cc @colinhacks since you might be able to quickly clarify if this is indeed a bug or just things working as intended - seems like not ideal behavior to me

@kiliman
Copy link
Collaborator

kiliman commented Jul 16, 2022

If you use my superjson version, it is correctly typed:
image

https://stackblitz.com/edit/node-cx46b4?file=app%2Froutes%2Findex.tsx

@machour
Copy link
Collaborator

machour commented Jan 22, 2023

Fixed in #3774 and released in 1.6.6

@machour machour closed this as completed Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants