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

Possible? Capture and return modified signature #10215

Closed
unional opened this issue Aug 8, 2016 · 5 comments
Closed

Possible? Capture and return modified signature #10215

unional opened this issue Aug 8, 2016 · 5 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@unional
Copy link
Contributor

unional commented Aug 8, 2016

TypeScript: 2.0.0

function factorial(num: number): number { ... }

// pfact signature: pfact(num: number): Promise<number>
const pfact = promisify(factorial)

AFAIK it is currently not possible, thus we need to do something like this:
https://github.com/types/npm-bluebird/blob/master/bluebird.d.ts#L333

Is it possible in the future, or it's just a hard limitation that it can't be done?

@yortus
Copy link
Contributor

yortus commented Aug 9, 2016

Would #5453 solve this?

@Igorbek
Copy link
Contributor

Igorbek commented Aug 9, 2016

For any given number of parameters it is possible and easy:

declare function promisify<T, R>(fn: (arg: T) => R): (arg: T) => Promise<R>;
declare function promisify<T1, T2, R>(fn: (arg1: T1, arg2: T2) => R): (arg1: T1, arg2: T2) => Promise<R>;

However the most general declaration would require #5453 (@yortus thanks, was looking for it when you replied).

@Igorbek
Copy link
Contributor

Igorbek commented Aug 9, 2016

BTW, I wanted to file suggestion/proposal for way more complicated scenarios like that:

declare function f<T>(arg: T): [T];
const pf = promisify(f); // it won't infer <T>(arg: T) => Promise<T> -- which is sad

@Igorbek
Copy link
Contributor

Igorbek commented Aug 11, 2016

@unional I described my thoughts on how we could express these types of signatures. Long read :) #10247

@unional
Copy link
Contributor Author

unional commented Aug 12, 2016

Thanks. I'll check it out

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Aug 15, 2016
@mhegazy mhegazy closed this as completed Sep 20, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

5 participants