1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(ext/web): Fix structuredClone Web API type declaration (any -> generic) (#22968)

Closes #22958 

Used the same type as in:
https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts#L26114

---------

Signed-off-by: Viktor Marinho <56888067+viktormarinho@users.noreply.github.com>
This commit is contained in:
Viktor Marinho 2024-03-25 18:44:49 -03:00 committed by GitHub
parent 8b454b560a
commit fb1aa4e6d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View file

@ -1124,10 +1124,10 @@ declare var MessagePort: {
*
* @category DOM APIs
*/
declare function structuredClone(
value: any,
declare function structuredClone<T = any>(
value: T,
options?: StructuredSerializeOptions,
): any;
): T;
/**
* An API for compressing a stream of data.

View file

@ -9,9 +9,12 @@ Deno.test("self.structuredClone", async () => {
const arrayOriginal = ["hello world"];
const channelOriginal = new MessageChannel();
const [arrayCloned, portTransferred] = self
.structuredClone([arrayOriginal, channelOriginal.port2], {
.structuredClone(
[arrayOriginal, channelOriginal.port2] as [string[], MessagePort],
{
transfer: [channelOriginal.port2],
});
},
);
assert(arrayOriginal !== arrayCloned); // not the same identity
assertEquals(arrayCloned, arrayOriginal); // but same value
channelOriginal.port1.postMessage("1");