Skip to content

Possible? Capture and return modified signature #10215

Closed

Description

@unional

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?

Activity

  1. yortus commented on Aug 9, 2016

    @yortus
    Contributor

    Would #5453 solve this?

  2. Igorbek commented on Aug 9, 2016

    @Igorbek
    Contributor

    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 (Troy Gerwien (@yortus) thanks, was looking for it when you replied).

  3. Igorbek commented on Aug 9, 2016

    @Igorbek
    Contributor

    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
  4. Igorbek commented on Aug 11, 2016

    @Igorbek
    Contributor

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

  5. unional commented on Aug 12, 2016

    @unional
    ContributorAuthor

    Thanks. I'll check it out

  6. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions