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-server-runtime): fix Jsonify for objects with toJSON function #7736

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

MichaelDeBoey
Copy link
Member

@MichaelDeBoey MichaelDeBoey commented Oct 22, 2023

I also added some extra tests for objects


Closes #7821

@changeset-bot
Copy link

changeset-bot bot commented Oct 22, 2023

⚠️ No Changeset found

Latest commit: 5aac416

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Expect<Equal<Pretty<Jsonify<{a: [1, "two", Date, undefined, false]}>>, {a: [1, "two", string, null, false]}>>,
Expect<Equal<Pretty<Jsonify<{a: [unknown, 1]}>>, {a: [unknown, 1]}>>,
// @ts-expect-error
Expect<Equal<Pretty<Jsonify<{a: MyClass}>>, {a: {a: string}}>>,
Copy link
Member Author

Choose a reason for hiding this comment

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

I can't seem to get these nested classes to work

@pcattori probably has a good idea where to look at

@@ -160,14 +167,31 @@ type _tests = [

// object
Expect<Equal<Pretty<Jsonify<{}>>, {}>>,
// @ts-expect-error
Expect<Equal<Pretty<Jsonify<{a: any}>>, {a: any}>>,
Copy link
Member Author

Choose a reason for hiding this comment

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

I also don't really get why this one is failing tbh 🤔
If I change this to be equal to {a?: any}, this passes though

Copy link
Contributor

@pcattori pcattori left a comment

Choose a reason for hiding this comment

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

@MichaelDeBoey could you split this up into smaller, more targeted PRs?

Expect<Equal<Jsonify<{ toJSON(): Date }>, unknown>>,
Expect<Equal<Jsonify<{ toJSON(): any }>, any>>,
Expect<Equal<Jsonify<{ toJSON(): undefined }>, never>>,
Expect<Equal<Jsonify<{ toJSON(): Date }>, string>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't checked the other test cases, but this one is incorrect.

let result = JSON.parse(JSON.stringify({ toJSON: () => new Date() }))
// => {}

So the result is an empty object, not a string. toJSON doesn't seem to always recursively serialize the return value.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was checking, which did respond with a string

let result = JSON.parse(JSON.stringify({ toJSON: () => Date() }))
// => 'Mon Oct 23 2023 03:45:02 GMT+0200 (Midden-Europese zomertijd)'

@MichaelDeBoey
Copy link
Member Author

MichaelDeBoey commented Oct 23, 2023

could you split this up into smaller, more targeted PRs?

@pcattori Can you explain how you would see the separate PRs?
For me this PR is fixing the toJSON and testing it for all possible use-cases

  • It's also adding these use-cases in the object case (which already works, except for MyClass)

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.

2 participants