Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[node] Add structuredClone global to node #59434

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions types/node/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ interface BigInt64Array extends RelativeIndexable<bigint> {}
interface BigUint64Array extends RelativeIndexable<bigint> {}
//#endregion ArrayLike.at() end

/**
* @since 17.0.0
josh- marked this conversation as resolved.
Show resolved Hide resolved
*
* Creates a deep clone of an object.
*/
declare function structuredClone<T>(value: T, transfer?: { transfer: any[] }): T;
josh- marked this conversation as resolved.
Show resolved Hide resolved

/*----------------------------------------------*
* *
* GLOBAL INTERFACES *
Expand Down
11 changes: 11 additions & 0 deletions types/node/test/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ declare var RANDOM_GLOBAL_VARIABLE: true;
gc();
}
}

// structuredClone
{
structuredClone(123); // $ExpectType 123
structuredClone('hello'); // $ExpectType "hello"
structuredClone({ test: 123 }); // $ExpectType { test: number; }
structuredClone([{ test: 123 }]); // $ExpectType { test: number; }[]

const arrayBuffer = new ArrayBuffer(0);
structuredClone({ test: arrayBuffer }, { transfer: [arrayBuffer] }); // $ExpectType { test: ArrayBuffer; }
}