1

Consider this:

function doIt(thing: SomeThing, iterations: number): void {
  // ...
}

class ThingProcessor{
  private state: {
    // how to avoid specifying the arguments again?
    action: (thing: SomeThing, iterations: number) => void
  };
}

In this example, I have to specify the doIt function parameters twice. I'd rather indicate that state.action is typeof(doIt), e.g. use the same signature as the doIt function.

Josh M.
  • 26,437
  • 24
  • 119
  • 200
  • 1
    Possible duplicate of [How to reuse function signature definition in TypeScript](https://stackoverflow.com/questions/47241357/how-to-reuse-function-signature-definition-in-typescript) – Heretic Monkey Jun 06 '18 at 18:51

1 Answers1

1

You can just use the typeof operator on the function to get it's type

function doIt(thing: SomeThing, iterations: number): void {
    // ...
}

class ThingProcessor {
    private state: {
        // how to avoid specifying the arguments again?
        action: typeof doIt;
    };
}
Titian Cernicova-Dragomir
  • 230,986
  • 31
  • 415
  • 357