Issue
I can define the interface of a function:
interface Handler {
(state: IState, action: IAction): IState;
}
Then I can declare a function that satisfies the interface:
let selectRegimen: Handler = function(state, action) {
return state;
};
But what about named (as in, not anonymous) function? Obviously, I could do something like this:
let selectRegimen: Handler = function selectRegiment(state, action) {
return state;
};
...but something feels strange about that syntax. Is there a better way to handle this?
Solution
There's no way to force a specific name in a named function expression just like there's no way to force a specific variable name to assign the function to.
What you are doing is fine though you could use a type alias instead of an interface if you find that better suits your taste:
type Handler = (state: IState, action: IAction) => IState;
Answered By - David Sherret
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.