Class-based cloning in #TypeScript is tricky. Ideas?
🟢 Approach 1:
abstract class SuperClass {
abstract clone(): this;
}
Problem: Subclass S can’t invoke its constructor and return the result. TS will complain that `this` could be an instance of a subclass of S; then type is indeed wrong.
🟢 Approach 2: structuredClone
Downsides:
A. Prototypes not preserved (*)
B. Private properties not copied
(B) is fatal for nested class instances.