Open samchon opened 1 month ago
As you mentioned, our clone
function should handle most JavaScript native objects. One thing that comes to my mind is that it will hurt bundle size, but accuracy is more important...
Maybe you should use https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Current
clone()
function considers only those native classes.Date
Set
Map
RegExp
However, there are much more native classes in the JavaScript, especially about binary handling.
So, I think that the
clone()
function should consider them.Uint8Array
Uint8ClampedArray
Uint16Array
BigInt64Array
Int8Array
Int16Array
Int32Array
BigInt64Array
Float32Array
Float64Array
ArrayBuffer
SharedArrayBuffer
DataView
Blob
File
Also, current
clone()
function is returning the sameT
type with its parameter, but it is not correct.The returned type must be casted, because non-native classes are converted to primitve object type.
To solve this problem, the
clone()
function needs to returnShallowed<T>
type like below.Related PR: https://github.com/toss/es-toolkit/pull/155