in eng/tools/typespec-migration-validation/src/document.ts [301:326]
function deepCopy<T>(value: T): T {
if (value === null || value === undefined) {
return value;
}
if (typeof value !== 'object') {
return value;
}
if (value instanceof Date) {
return new Date(value.getTime()) as unknown as T;
}
if (Array.isArray(value)) {
return value.map(item => deepCopy(item)) as unknown as T;
}
const result: Record<string, any> = {};
for (const key in value) {
if (Object.prototype.hasOwnProperty.call(value, key)) {
result[key] = deepCopy((value as Record<string, any>)[key]);
}
}
return result as T;
}