radash
radash copied to clipboard
Improve the type coverage of clone function
-
The current clone function throws an error when the parameter is 'undefined' or 'null', even though 'null' is considered as 'object' by TS.
-
Since the current clone function creates an empty object and assign the old props, the new object is actually not an copy of the given object when the given object is a class instance. It loses the parameter's class definition.
-
The current clone function can only clone objects and arrays but not primitive types or functions. By adding a primitive check, its type coverage can be increased.