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

Asyncify lost the general return type #178

Closed
linonetwo opened this issue Jan 23, 2021 · 4 comments
Closed

Asyncify lost the general return type #178

linonetwo opened this issue Jan 23, 2021 · 4 comments

Comments

@linonetwo
Copy link

linonetwo commented Jan 23, 2021

I have a 'get' method like this:

Screen Shot 2021-01-23 at 23 33 11

And I Asyncify it through this:

/**
 * To call services that is located in main process, from the renderer process, we use IPC.invoke, so all method should now promisify
 * Note this type only promisify methods that return things, not methods that returns observable.
 */
type AsyncifyProxy<OriginalProxy, K extends ConditionalKeys<OriginalProxy, Function> = ConditionalKeys<OriginalProxy, Function>> = {
  [P in K]: Asyncify<OriginalProxy[P]>;
};

Then the result lost the type:
Screen Shot 2021-01-23 at 23 34 06

I can see it don't allow the general type now:

Screen Shot 2021-01-23 at 23 38 15

it used to know the return type based on the input...

Screen Shot 2021-01-23 at 23 35 13

Is it possible to solve this?

https://github.com/sindresorhus/type-fest/blob/main/source/asyncify.d.ts

@sindresorhus
Copy link
Owner

// @papb

@linonetwo
Copy link
Author

Playground here:

Playground Link

@papb
Copy link
Contributor

papb commented Feb 10, 2021

Oops, sorry for the delay, I missed this notification.

Hmm... This is a TypeScript limitation, unfortunately. The simple act of writing (...args: Parameters<F>): ReturnType<F> already "settles" all generics into their widest type (usually unknown).

I tried for some time to find another workaround to keep at least the most common generic usages but I couldn't.

Here are some related TS issues: microsoft/TypeScript#39594, microsoft/TypeScript#10247, microsoft/TypeScript#37835.

This problem also happens with SetReturnType.

Should we add a note to the docs that it does not work with functions with generic types?

@linonetwo
Copy link
Author

linonetwo commented Feb 13, 2021

Thank you, I also confirmed today from TS member, this is a design limintation microsoft/TypeScript#42706

Seems there is no official workaround currently.

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

3 participants