-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Labels
area/ecmascriptRelates to ecmascript moduleRelates to ecmascript modulearea/vrotscRelates to `vrotsc` moduleRelates to `vrotsc` moduleeffort/lowkind/featureNew Feature to the projectNew Feature to the projectlang/typescriptRelated to typescript codeRelated to typescript codepriority/lowtriage/acceptedThe issue was accepted and will be doneThe issue was accepted and will be doneversion/minorIntroduces a non-breaking feature or changeIntroduces a non-breaking feature or change
Description
Description
It is a common task that we need to deep clone an object and change it's values without affecting the original. It might be useful to implement a shim/polyfil for structuredClone() so that we have that function out of the box. This would lead to more consistency and simplicity across the different approaches of implementing similar solution (most of which actually do not deep clone the object and lead to issues and bugs later down the line).
- the options.trasfer array implementation is nice to have but not a must
Alternatives
Additional Context
https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone
It can be something as simple as
if (source === undefined || source === null) {
throw new Error("Source value is mandatory.");
}
return JSON.parse(JSON.stringify(source));
Note that this has some restrictions, e.g. works mainly for simple objects
Metadata
Metadata
Assignees
Labels
area/ecmascriptRelates to ecmascript moduleRelates to ecmascript modulearea/vrotscRelates to `vrotsc` moduleRelates to `vrotsc` moduleeffort/lowkind/featureNew Feature to the projectNew Feature to the projectlang/typescriptRelated to typescript codeRelated to typescript codepriority/lowtriage/acceptedThe issue was accepted and will be doneThe issue was accepted and will be doneversion/minorIntroduces a non-breaking feature or changeIntroduces a non-breaking feature or change