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 for serializable objects? #855

Open
chen-ye opened this issue Apr 2, 2024 · 3 comments
Open

Type for serializable objects? #855

chen-ye opened this issue Apr 2, 2024 · 3 comments

Comments

@chen-ye
Copy link

chen-ye commented Apr 2, 2024

Would it make sense to create a type for serializable objects?

Similar to Jsonify et al., this would match values that could losslessly be deep-copied via structuredClone or postMessage.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@sindresorhus
Copy link
Owner

How would you use it?


For reference, the algorithm for structuredClone: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm

@chen-ye
Copy link
Author

chen-ye commented Apr 3, 2024

My two use cases are similar to how I currently use the Jsonify family of types:

  • To ensure that an application state object as passed between a web worker and the main thread remains serializable
  • To more strongly type the outputs of a structuredClone call

@sindresorhus
Copy link
Owner

It's more like Jsonifiable. Could maybe be called StructuredCloneable.

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