How to specify type of class method

Viewed 40

Is there a way to specify the type of a class method using a type that I've already defined elsewhere?

type AnimalFunctions = {
  roar(word: string): Promise<void>;
  eat(): Promise<boolean>;
};

export class Animal {
  constructor()
  async myRoar(param) {
  }
}

I want to be able to use AnimalFunctions["roar"] as the type for the myRoar function, so that it types both the params as well as the return type. I'm kind of blanking on what the syntax should be.

0 Answers
Related