structuredClone
will be available in lib.dom
of TypeScript v4.7 (as of 2022-05-19 it is currently in beta, but will be out soon). You can see where structuredClone
was added to TypeScript here.
If you need to add it to your project temporarily until you can upgrade TypeScript, you can do that by putting the following definitions from the commit linked above into a structuredClone.d.ts
file in your project (the base name doesn't matter, but the .d.ts
does):
interface WindowOrWorkerGlobalScope {
structuredClone(value: any, options?: StructuredSerializeOptions): any;
}
declare function structuredClone( value: any, options?: StructuredSerializeOptions): any;
(StructuredSerializeOptions
is already defined by lib.dom.d.ts
for postMessage
, so we don't need to add it.)
Then just remove that file when you've upgraded later.