Defining TypeScript callback type

后端 未结 8 1158
情话喂你
情话喂你 2020-12-12 11:53

I\'ve got the following class in TypeScript:

class CallbackTest
{
    public myCallback;

    public doWork(): void
    {
        //doing some work...
               


        
8条回答
  •  难免孤独
    2020-12-12 12:05

    To go one step further, you could declare a type pointer to a function signature like:

    interface myCallbackType { (myArgument: string): void }
    

    and use it like this:

    public myCallback : myCallbackType;
    

提交回复
热议问题