type-fest icon indicating copy to clipboard operation
type-fest copied to clipboard

Type for serializable objects?

Open chen-ye opened this issue 4 months ago • 3 comments

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

chen-ye avatar Apr 02 '24 22:04 chen-ye

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

sindresorhus avatar Apr 03 '24 07:04 sindresorhus

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

chen-ye avatar Apr 03 '24 16:04 chen-ye

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

sindresorhus avatar Apr 03 '24 16:04 sindresorhus