Issue
type Func = (foo:string) => void
// function expression
const myFunctionExpression:Func = function(foo) {
console.log(foo)
}
In the Typescript snippet above, I am using type alias to annotate the variable in a function expression.
The type alias:
type Func = (foo:string) => void
is reusable in another function expression to reduce repetition.
My question is: Is there a way to reuse this type alias to annotate a function declaration ?
// function declaration
function myFunctionDeclaration(foo:string):void {
console.log(foo)
}
After some search online, I cannot seem to find such syntax, what am I missing?
Thanks
update:
At the time of this writing there is a ticket on github requesting for this feature: Suggestion: Type annotations and interfaces for function declarations #22063 (thanks to comment from @jcalz)
Solution
At time of writing (TypeScript 3.4), there is not a way to apply a type to a function declaration.
Answered By - Ryan Cavanaugh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.