diff options
Diffstat (limited to 'std/node/_util')
-rw-r--r-- | std/node/_util/_util_promisify.ts | 6 | ||||
-rw-r--r-- | std/node/_util/_util_promisify_test.ts | 24 |
2 files changed, 18 insertions, 12 deletions
diff --git a/std/node/_util/_util_promisify.ts b/std/node/_util/_util_promisify.ts index 03ebeba04..6aeee8ecf 100644 --- a/std/node/_util/_util_promisify.ts +++ b/std/node/_util/_util_promisify.ts @@ -56,7 +56,11 @@ class NodeInvalidArgTypeError extends TypeError { } } -export function promisify(original: Function): Function { +export function promisify( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + original: (...args: any[]) => void, + // eslint-disable-next-line @typescript-eslint/no-explicit-any +): (...args: any[]) => Promise<any> { if (typeof original !== "function") { throw new NodeInvalidArgTypeError("original", "Function", original); } diff --git a/std/node/_util/_util_promisify_test.ts b/std/node/_util/_util_promisify_test.ts index 67ca6af58..6271a8581 100644 --- a/std/node/_util/_util_promisify_test.ts +++ b/std/node/_util/_util_promisify_test.ts @@ -29,6 +29,9 @@ import { import { promisify } from "./_util_promisify.ts"; import * as fs from "../fs.ts"; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +type VoidFunction = (...args: any[]) => void; + const readFile = promisify(fs.readFile); const customPromisifyArgs = Symbol.for("nodejs.util.promisify.customArgs"); @@ -87,7 +90,7 @@ Deno.test("Custom promisify args", async function testPromisifyCustomArgs() { const firstValue = 5; const secondValue = 17; - function fn(callback: Function): void { + function fn(callback: VoidFunction): void { callback(null, firstValue, secondValue); } @@ -101,7 +104,7 @@ Deno.test("Custom promisify args", async function testPromisifyCustomArgs() { Deno.test( "Multiple callback args without custom promisify args", async function testPromisifyWithoutCustomArgs() { - function fn(callback: Function): void { + function fn(callback: VoidFunction): void { callback(null, "foo", "bar"); } const value = await promisify(fn)(); @@ -112,7 +115,7 @@ Deno.test( Deno.test( "Undefined resolved value", async function testPromisifyWithUndefinedResolvedValue() { - function fn(callback: Function): void { + function fn(callback: VoidFunction): void { callback(null); } const value = await promisify(fn)(); @@ -123,7 +126,7 @@ Deno.test( Deno.test( "Undefined resolved value II", async function testPromisifyWithUndefinedResolvedValueII() { - function fn(callback: Function): void { + function fn(callback: VoidFunction): void { callback(); } const value = await promisify(fn)(); @@ -134,7 +137,7 @@ Deno.test( Deno.test( "Resolved value: number", async function testPromisifyWithNumberResolvedValue() { - function fn(err: Error | null, val: number, callback: Function): void { + function fn(err: Error | null, val: number, callback: VoidFunction): void { callback(err, val); } const value = await promisify(fn)(null, 42); @@ -145,7 +148,7 @@ Deno.test( Deno.test( "Rejected value", async function testPromisifyWithNumberRejectedValue() { - function fn(err: Error | null, val: null, callback: Function): void { + function fn(err: Error | null, val: null, callback: VoidFunction): void { callback(err, val); } await assertThrowsAsync( @@ -157,9 +160,8 @@ Deno.test( ); Deno.test("Rejected value", async function testPromisifyWithAsObjectMethod() { - const o: { fn?: Function } = {}; - const fn = promisify(function (cb: Function): void { - // @ts-expect-error TypeScript + const o: { fn?: VoidFunction } = {}; + const fn = promisify(function (this: unknown, cb: VoidFunction): void { cb(null, this === o); }); @@ -177,7 +179,7 @@ Deno.test( ); const stack = err.stack; - const fn = promisify(function (cb: Function): void { + const fn = promisify(function (cb: VoidFunction): void { cb(null); cb(err); }); @@ -203,7 +205,7 @@ Deno.test("Test error", async function testInvalidArguments() { a: number, b: number, c: number, - cb: Function, + cb: VoidFunction, ): void { errToThrow = new Error(`${a}-${b}-${c}-${cb}`); throw errToThrow; |