type Func = (param:string) => void
// implementing a function expression
const myFunctionExpression:Func = function(param) {
console.log(param)
}
Within the TypeScript code snippet above, I have utilized a type alias to define the variable in a function expression.
The defined type alias:
type Func = (param:string) => void
can be reused in other function expressions, reducing redundancy in the code.
My query is: Is there a method to apply this type alias for annotating a function declaration as well?
// defining a function
function myFunctionDeclaration(param:string):void {
console.log(param)
}
Despite researching online, I have yet to come across syntax that allows for such functionality. What might I be overlooking?
Thank you
update:
An ongoing request on GitHub is seeking this feature: Suggestion: Type annotations and interfaces for function declarations #22063 (credit to comment from @jcalz)