I have the following class in TypeScript:
class CallbackTest { public myCallback; public doWork(): void {
I use the class as follows:
var test = new CallbackTest(); test.myCallback = () => alert("done"); test.doWork();
The code works, so it displays a message box as expected.
My question is: is there any type that I can provide for my field of class myCallback ? The public field myCallback is now of type any , as shown above. How to determine the signature of a callback method? Or can I just set the type of the callback type? Or can I do it? Should I use any (implicit / explicit)?
I tried something like this, but this did not work (compile-time error):
public myCallback: ();
I could not find any explanation for this online, so I hope you can help me.
types callback typescript
nikeee Oct 30 2018-12-12T00: 00Z
source share