I do have some problems with declaration of Redux Action Type. By definition the Redux Action should have type
property and could have some other properties.
According to TypeScript interfaces page in HandBook (see "Excess Property Checks") i could do it like that:
interface IReduxAction {
type: string;
[propName: string]: any;
}
And seems it work in some situations (like declaration of a variable)
const action: IReduxAction = {
type: 'hello',
value: 'world'
};
But if i am trying to declare function that is using the action:
function hello(state = {}, action: IReduxAction) {
return { type: action.type, text: action.text };
}
It fails with the message "Property text
does not exist on type IReduxAction
".
What am i doing wrong? How to declare the general action type?
Live example on TypeScript playground is here
P.S. I checked "similar" questions, like Why am I getting an error "Object literal may only specify known properties"?, and haven't found the solution there...
P.S.S. Apparently it does work in latest version of TypeScript.