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:
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
|
* @category DOM APIs
|
||||||
*/
|
*/
|
||||||
declare function structuredClone(
|
declare function structuredClone<T = any>(
|
||||||
value: any,
|
value: T,
|
||||||
options?: StructuredSerializeOptions,
|
options?: StructuredSerializeOptions,
|
||||||
): any;
|
): T;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An API for compressing a stream of data.
|
* An API for compressing a stream of data.
|
||||||
|
|
|
@ -9,9 +9,12 @@ Deno.test("self.structuredClone", async () => {
|
||||||
const arrayOriginal = ["hello world"];
|
const arrayOriginal = ["hello world"];
|
||||||
const channelOriginal = new MessageChannel();
|
const channelOriginal = new MessageChannel();
|
||||||
const [arrayCloned, portTransferred] = self
|
const [arrayCloned, portTransferred] = self
|
||||||
.structuredClone([arrayOriginal, channelOriginal.port2], {
|
.structuredClone(
|
||||||
|
[arrayOriginal, channelOriginal.port2] as [string[], MessagePort],
|
||||||
|
{
|
||||||
transfer: [channelOriginal.port2],
|
transfer: [channelOriginal.port2],
|
||||||
});
|
},
|
||||||
|
);
|
||||||
assert(arrayOriginal !== arrayCloned); // not the same identity
|
assert(arrayOriginal !== arrayCloned); // not the same identity
|
||||||
assertEquals(arrayCloned, arrayOriginal); // but same value
|
assertEquals(arrayCloned, arrayOriginal); // but same value
|
||||||
channelOriginal.port1.postMessage("1");
|
channelOriginal.port1.postMessage("1");
|
||||||
|
|
Loading…
Reference in a new issue