December 2017
Beginner
372 pages
10h 32m
English
We can modify our callback signature in doWork to be more concise by using TypeScript interfaces as shown here:
interface ICallBack{ (boards: Board[], status: string) : void;}function doWork(clientName: string, callback: ICallBack): void{ let response:Board[]; // web service call based on id and in response we get list of Boards // then we call our function passing required values callback(response, "Success");}
Here we defined an interface with our callback signature and used the interface type to mention the type of the second parameter in the doWork method.
This way we just made our code more concise and clean; additionally, now we can use the same callback signature in multiple places.
Read now
Unlock full access