From 1f2dfaad9b0fe9ec391e8be149f64f9f40d07d8f Mon Sep 17 00:00:00 2001 From: Aaron Bassett Date: Fri, 26 May 2023 14:03:07 -0400 Subject: [PATCH 1/2] fix: update pcall types to properly infer return type --- src/_utils.ts | 5 ++++- src/resolve.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/_utils.ts b/src/_utils.ts index 89820be..bf41760 100644 --- a/src/_utils.ts +++ b/src/_utils.ts @@ -6,7 +6,10 @@ export function normalizeSlash(string_) { return string_.replace(/\\/g, "/"); } -export function pcall(function_, ...arguments_) { +export function pcall any>( + function_: TFn, + ...arguments_: Parameters +): Promise> { try { return Promise.resolve(function_(...arguments_)).catch((error) => perr(error) diff --git a/src/resolve.ts b/src/resolve.ts index cb831ec..011295f 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -124,11 +124,11 @@ function _resolve(id: string, options: ResolveOptions = {}): string { return pathToFileURL(realPath).toString(); } -export function resolveSync(id: string, options?: ResolveOptions): string { +export function resolveSync(id: string, options?: ResolveOptions) { return _resolve(id, options); } -export function resolve(id: string, options?: ResolveOptions): Promise { +export function resolve(id: string, options?: ResolveOptions) { return pcall(resolveSync, id, options); } From 49b7bc8b33abf72ccf0026b0c25acf5b0ea4c2c7 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 19 Jun 2023 13:57:58 +0200 Subject: [PATCH 2/2] add explicit types --- src/resolve.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/resolve.ts b/src/resolve.ts index 011295f..593d58a 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -124,19 +124,22 @@ function _resolve(id: string, options: ResolveOptions = {}): string { return pathToFileURL(realPath).toString(); } -export function resolveSync(id: string, options?: ResolveOptions) { +export function resolveSync(id: string, options?: ResolveOptions): string { return _resolve(id, options); } -export function resolve(id: string, options?: ResolveOptions) { +export function resolve(id: string, options?: ResolveOptions): Promise { return pcall(resolveSync, id, options); } -export function resolvePathSync(id: string, options?: ResolveOptions) { +export function resolvePathSync(id: string, options?: ResolveOptions): string { return fileURLToPath(resolveSync(id, options)); } -export function resolvePath(id: string, options?: ResolveOptions) { +export function resolvePath( + id: string, + options?: ResolveOptions +): Promise { return pcall(resolvePathSync, id, options); }