Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#59434 [node] Add structuredClone global to…
Browse files Browse the repository at this point in the history
… node by @josh-

* Add structuredClone to node

* Change type of transfer to take readonly array of TransferListItems

* Update format of @SInCE tag
  • Loading branch information
josh- authored Apr 26, 2022
1 parent 7420fbb commit 1ca333e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions types/node/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ interface BigInt64Array extends RelativeIndexable<bigint> {}
interface BigUint64Array extends RelativeIndexable<bigint> {}
//#endregion ArrayLike.at() end

/**
* @since v17.0.0
*
* Creates a deep clone of an object.
*/
declare function structuredClone<T>(
value: T,
transfer?: { transfer: ReadonlyArray<import('worker_threads').TransferListItem> },
): T;

/*----------------------------------------------*
* *
* 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; }
}

0 comments on commit 1ca333e

Please sign in to comment.