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

[Bug]: StaticCanvas.toJSON() is an alias to toObject() but doesnt take argument propertiesToInclude in 6.4.3 #10220

Closed
7 tasks done
tneullas opened this issue Oct 16, 2024 · 4 comments

Comments

@tneullas
Copy link

tneullas commented Oct 16, 2024

CheckList

  • I agree to follow this project's Code of Conduct
  • I have read and followed the Contributing Guide
  • I have read and followed the Issue Tracker Guide
  • I have searched and referenced existing issues and discussions
  • I am filing a BUG report.
  • I have managed to reproduce the bug after upgrading to the latest version
  • I have created an accurate and minimal reproduction

Version

6.4.3

In What environments are you experiencing the problem?

Chrome

Node Version (if applicable)

20.11.0

Steps To Reproduce

  1. Call StaticCanvas.toJSON(['lockMovementX'])

Expected Behavior

Expect corresponding properties to be exported

Actual Behavior

Nothing is exported because it is now an alias to toObject() without transferring propertiesToInclude parameter.

Error Message & Stack Trace

Get ts error :  Expected 0 arguments, but got 1.ts(2554)
@tneullas tneullas changed the title [Bug]: Object.toJSON() is an alias to toObject() but doesnt take argument propertiesToInclude in 6.4.3 [Bug]: StaticCanvas.toJSON() is an alias to toObject() but doesnt take argument propertiesToInclude in 6.4.3 Oct 16, 2024
@asturur
Copy link
Member

asturur commented Oct 16, 2024

ToJSON is a delegate is not an alias.
ToJSON is a javascript reserved method and works in that way, it takes specific arguments that come from JSON.stringify.

Have a look here and look the example of BigInt
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

@asturur asturur closed this as completed Oct 16, 2024
@tneullas
Copy link
Author

Thanks for the explanation @asturur , I did not know it was a reserved method.
Though jsdoc, documentation and examples are confusing about the subject :
http://fabricjs.com/docs/fabric.Canvas.html#toJSON

@asturur
Copy link
Member

asturur commented Oct 17, 2024

Yes those are the 5.3.1 docs, the newer i think have been corrected.

https://fabricjs.github.io/api/classes/canvas/#tojson

the new doc has a better description but still a wrong example.

@tneullas
Copy link
Author

Oh, didnt know about new docs, thanks for the link and the times :)

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

No branches or pull requests

2 participants