Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type of ReturnType passed to mem options is incorrect #28

Closed
henhal opened this issue Oct 4, 2021 · 1 comment
Closed

Type of ReturnType passed to mem options is incorrect #28

henhal opened this issue Oct 4, 2021 · 1 comment

Comments

@henhal
Copy link
Contributor

henhal commented Oct 4, 2021

The current interface in index.d.ts:

	<ArgumentsType extends any[], ReturnType, CacheKeyType>(
		fn: (...arguments: ArgumentsType) => PromiseLike<ReturnType>,
		options?: pMemoize.Options<ArgumentsType, CacheKeyType, PromiseLike<ReturnType>>
	): (...arguments: ArgumentsType) => Promise<ReturnType>;

This means that if you pass a fn returning Promise<MyType>, and you need to use your own custom cache, you need to pass e.g. Map<string, {data: MyType, maxAge: number}>, which is incorrect; the cache will store Promise<MyType> in the data field of each cache entry.

Currently the only way to compile code using p-memoize and a custom cache is to type the custom cache values as any.

By using the same type for the return type of fn and the data entries, the error is resolved.

Fixed by #27

@sindresorhus
Copy link
Owner

Fixed by #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants