I'm looking to create a function that can clone either an object or array. It should return the same type as the argument passed in, but only objects and arrays are accepted.
Does anyone know how to accomplish this task?
export function clone<T>(target: T): T {
return JSON.parse(JSON.stringify(target))
}
// This should result in failure
clone('asdasd')
// These should be successful
clone({})
clone([])