Fix stringify error from resource deployment extension (#14059)

* Fix stringify error from resource deployment extension

* add comment
This commit is contained in:
Charles Gagnon
2021-01-26 12:00:05 -08:00
committed by GitHub
parent 1a84db089a
commit d828a1f042
2 changed files with 25 additions and 1 deletions

View File

@@ -71,3 +71,22 @@ export async function tryExecuteAction<T>(action: () => T | PromiseLike<T>): Pro
}
return { result, error };
}
export function deepClone<T>(obj: T): T {
if (!obj || typeof obj !== 'object') {
return obj;
}
if (obj instanceof RegExp) {
// See https://github.com/Microsoft/TypeScript/issues/10990
return obj as any;
}
const result: any = Array.isArray(obj) ? [] : {};
Object.keys(<any>obj).forEach((key: string) => {
if ((<any>obj)[key] && typeof (<any>obj)[key] === 'object') {
result[key] = deepClone((<any>obj)[key]);
} else {
result[key] = (<any>obj)[key];
}
});
return result;
}