mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -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:
parent
8b454b560a
commit
fb1aa4e6d2
2 changed files with 9 additions and 6 deletions
6
ext/web/lib.deno_web.d.ts
vendored
6
ext/web/lib.deno_web.d.ts
vendored
|
@ -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.
|
||||
|
|
|
@ -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], {
|
||||
transfer: [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");
|
||||
|
|
Loading…
Reference in a new issue