Skip to content

Add a Serialisable type for the structured clone algorithmΒ #61908

Open
@BlackAsLight

Description

@BlackAsLight

πŸ” Search Terms

"Serialisable", "structured clone"

βœ… Viability Checklist

⭐ Suggestion

It would be nice to have a type for the structured clone algorithm that is passed to worker.postMessage so one can get type info about whether a value will throw a DataCloneError or not.

We have a Transferable type, which is quite nice.

Additionally, a type that converts acceptable types to what they'd end up as on the other side would also be nice. For example, some Error types are converted to Error when passed through.

πŸ“ƒ Motivating Example

This feature would improve the language as it offers missing type information

πŸ’» Use Cases

  1. What do you want to use this for?
    I'd like to use this type to refine the type safety of my jsr:@doctor/thread while adding no additional runtime overhead.
  2. What shortcomings exist with current approaches?
    The shortcoming is that it's currently an any type. Users need to research what types are serialisable for their given runtime.
  3. What workarounds are you using in the meantime?
    None at the moment, but I'm exploring the difficulty in creating the type myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions