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

AsyncReturnType doesn't work with arguments #98

Closed
fregante opened this issue Apr 15, 2020 · 2 comments
Closed

AsyncReturnType doesn't work with arguments #98

fregante opened this issue Apr 15, 2020 · 2 comments

Comments

@fregante
Copy link

fregante commented Apr 15, 2020

I'm not able to use this type:

type PromisedStringFunction = (query: string) => Promise<string>;
type ShouldBeAString = AsyncReturnType<PromisedStringFunction>;

I get this error:

Type '(query: string) => Promise<string>' does not satisfy the constraint 'AsyncFunction'.
  Types of parameters 'query' and 'args' are incompatible.
    Type 'unknown' is not assignable to type 'string'.ts(2344)

I had my own AsyncReturnType and it worked well with any, not unknown

@buschtoens
Copy link
Contributor

Can you confirm you're really on the latest version? It works for me:

type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value> ? Value : Otherwise;
type AsyncFunction = (...args: any[]) => Promise<unknown>;
type AsyncReturnType<Target extends AsyncFunction> = PromiseValue<ReturnType<Target>>;

type PromisedStringFunction = (query: string) => Promise<string>;
type ShouldBeAString = AsyncReturnType<PromisedStringFunction>;

TS Playground

@fregante
Copy link
Author

Fixed by #96

Sorry!

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

Successfully merging a pull request may close this issue.

2 participants