Open
Description
π Search Terms
"Serialisable", "structured clone"
β Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
β 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
- What do you want to use this for?
I'd like to use this type to refine the type safety of myjsr:@doctor/thread
while adding no additional runtime overhead. - 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. - What workarounds are you using in the meantime?
None at the moment, but I'm exploring the difficulty in creating the type myself.