Typing Wrapper Functions in Typescript
Motivation Very often in TypeScript, we would like to wrap an existing function into a wrapper function, with some additional preprocessing or postprocessing. For example, function existingFunc(arg1: number, arg2: string): number { return arg1 + arg2.length; } function wrapperFunc(arg1: number, arg2: string): number { // Preprocess arg1 and arg2... return existingFunc(arg1, arg2); } In this case, the wrapper function often shares the same parameter types and return type. If the existing function is already typed, we can reuse those typing information. This would reduce redundancy and is also able to reflect any changes that would happen in the typing of the existing function in the future. ...