Skip to content

Commit

Permalink
Use TypeScript's Awaited utility type instead of our custom EnsurePro…
Browse files Browse the repository at this point in the history
…mise type
  • Loading branch information
joliss committed Mar 6, 2024
1 parent 3ee8f38 commit 38d84c3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,14 @@ export default function buildMemoizer(
fn: <FN extends (...args: never) => unknown>(
fn: FN,
opt?: Partial<MemoizerOptions>
) => Promise<(...args: Parameters<FN>) => EnsurePromise<ReturnType<FN>>>
) => Promise<(...args: Parameters<FN>) => Promise<Awaited<ReturnType<FN>>>>
getCacheFilePath: (
fn: (...args: never) => unknown,
args: unknown[],
opt: Partial<MemoizerOptions>
) => string
invalidate: (cacheId?: string) => Promise<void>
}

type EnsurePromise<T> = T extends PromiseLike<unknown> ? T : Promise<T>;
```

## Options
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,9 @@ export default function buildMemoizer(
await initCache(memoizerOptions.cachePath || '')
return memoizeFn(fn as never, opt) as unknown as (
...args: Parameters<FN>
) => EnsurePromise<ReturnType<FN>>
) => Promise<Awaited<ReturnType<FN>>>
},
getCacheFilePath: getCacheFilePathBound,
invalidate: invalidateCache,
}
}

type EnsurePromise<T> = T extends PromiseLike<unknown> ? T : Promise<T>;

0 comments on commit 38d84c3

Please sign in to comment.