-
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
fix(remix-react): allow readonly arrays in SerializeType
#3774
fix(remix-react): allow readonly arrays in SerializeType
#3774
Conversation
`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 detectedLatest commit: 485de1c The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
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 |
SerializeType
@@ -1350,7 +1350,7 @@ type SerializeType<T> = T extends JsonPrimitives | |||
? null | |||
: SerializeType<T[k]>; | |||
} | |||
: T extends (infer U)[] | |||
: T extends ReadonlyArray<infer U> |
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.
Does this allow regular arrays as well?
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.
yes, because Array<unknown>
extends ReadonlyArray<unknown>
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.
@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?
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.
Here's the docs on the infer keyword: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#inferring-within-conditional-types
Here's the docs on ReadonlyArray: https://www.typescriptlang.org/docs/handbook/2/objects.html#the-readonlyarray-type
And here's a simplified example of it in action: https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEYD2A7AzgF3hkmBc8AgjDFAJ4A8KArgLYBGIMAfAFCsZkAOCAKrlgC82biCQAzbAPggAHjhTA08AEogowVBDLFSlAJYpxTeL2bwA-KfgEUIAG5NWAemfx38AHoWgA
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.
Thanks!
Closes: #3762
Testing Strategy:
Patched
node_modules
in the package in the original repo and confirmed that it fixed the issue.