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

fix(remix-react): allow readonly arrays in SerializeType #3774

Merged
merged 2 commits into from Jul 18, 2022

Conversation

JNaftali
Copy link
Contributor

Closes: #3762

  • Docs
  • Tests

Testing Strategy:

Patched node_modules in the package in the original repo and confirmed that it fixed the issue.

`SerializeType` should allow any type that can be safely serialized by the `JSON` module, and since `ReadonlyArray` is just an `Array` at runtime it qualifies. Since Array extends ReadonlyArray we should be able to switch the check from in `SerializeType` from `Array` to `ReadonlyArray` to achieve this.
@changeset-bot
Copy link

changeset-bot bot commented Jul 16, 2022

🦋 Changeset detected

Latest commit: 485de1c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
remix Patch
@remix-run/react Patch
@remix-run/dev Patch
@remix-run/eslint-config Patch
@remix-run/serve Patch
@remix-run/server-runtime Patch
@remix-run/cloudflare Patch
@remix-run/node Patch
@remix-run/deno Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/express Patch
@remix-run/netlify Patch
@remix-run/vercel Patch
create-remix Patch
@remix-run/architect Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@MichaelDeBoey MichaelDeBoey changed the title Allow readonly arrays in SerializeType fix(remix-react): allow readonly arrays in SerializeType Jul 17, 2022
@@ -1350,7 +1350,7 @@ type SerializeType<T> = T extends JsonPrimitives
? null
: SerializeType<T[k]>;
}
: T extends (infer U)[]
: T extends ReadonlyArray<infer U>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this allow regular arrays as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, because Array<unknown> extends ReadonlyArray<unknown>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JNaftali Can you point us to the docs of this please?
Been looking into it, but can't find that.

Maybe @mattpocock can also help out on this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type error when inferring the type of ReadonlyArrays returned from useLoaderData
4 participants