Reputation: 11812
I have a StoryOptions
object, that one of its properties is actionFn
, which when called, will return a function. (I'm making use of function currying).
This actionFn
needs to accept an object of type ActionBundle
, and it will return a function that accepts a Payload
and returns a ReduxAction
.
How do I define the StoryOptions
interface in typescript?
I have tried:
interface StoryOptions {
baseName: string;
actionFn(actions: ActionBundle): ((payload: Payload): ReduxAction);
}
But this tells me:
'ReduxAction' only refers to a type, but is being used as a value here.ts(2693)
Upvotes: 2
Views: 5361
Reputation: 19957
It should be
interface StoryOptions {
actionFn(actions: ActionBundle): (payload: Payload) => ReduxAction;
}
Two ways you can specify a callable interface in TS.
type Callable = { (...args: any[]): any }
// or
type Callable = (...args: any[]) => any
With 1st syntax, the surrounding { }
is required. That's what you missed.
Upvotes: 2
Reputation: 1073
You can show that it is a function this way:
interface StoryOptions {
baseName: string;
actionFn(actions: ActionBundle): ((payload: Payload) => ReduxAction);
}
Upvotes: 2