In a TypeScript web project I am using structuredClone
to deep-clone an AxiosError
object from the Axios library, defined as:
export interface AxiosError<T = any> extends Error {
//...
isAxiosError: boolean;
toJSON: () => object;
}
interface Error {
name: string;
// ...
}
My code:
function f(axiosError: AxiosError<ArrayBuffer>): void {
const copy = window.structuredClone(axiosError);
const a = typeof axiosError.name === "undefined"; // false
const b = typeof axiosError.isAxiosError === "undefined"; // false
const c = typeof copy.name === "undefined"; // false
const d = typeof copy.isAxiosError === "undefined"; // true
}
Upon further investigation, it appears that all of the parent properties are cloned, but the child properties are not. Why? I can reproduce this in Firefox and Chrome.