I have the following code:
//********** From Redux type declarations ************
export interface Action<T = any> {
type: T
}
export interface AnyAction extends Action {
// Allows any extra properties to be defined in an action.
[extraProps: string]: any
}
//***********************************
type ActionHandler<TState> = (state: TState, action: AnyAction) => TState
interface SomeState {
prop1: number
prop2: string
}
interface FooAction extends Action {
prop2: string
}
//This also doesnt work
// interface FooAction extends AnyAction {
// prop2: string
// }
const foo: ActionHandler<SomeState> = (state: SomeState, action: FooAction): SomeState => {
return {
...state,
prop2: action.prop2
}
}
And when I compile, I get the following error:
Type '(state: SomeState, action: FooAction) => SomeState' is not assignable to type 'ActionHandler<SomeState>'.
Types of parameters 'action' and 'action' are incompatible.
Property 'prop2' is missing in type 'AnyAction' but required in type 'FooAction'.ts(2322)
Any idea why do I get this error if AnyAction
allows adding dynamic keys?