I am looking to create an interface that can have properties of the same type, regardless of the content. For example:
type Reducer<S, P> = (state: S, payload: P) => S
interface Reducers {
[name: string]: Reducer
}
This is how I am trying to implement it:
interface MyState {
foo?: string
bar?: string
}
const reducers: Reducers = {
r1: (state: MyState, payload: string) => {
return {foo: payload}
}
}
Unfortunately, I am getting a compilation error. The error message is:
Error TS2314: Generic type 'Reducer' requires 2 type argument(s).
Can someone please advise me on what I am doing incorrectly?