ratson / react-intl-redux

Redux binding for React Intl.
MIT License
298 stars 48 forks source link

Usage with TypeScript #48

Closed mehmetnyarar closed 6 years ago

mehmetnyarar commented 6 years ago

I'm trying to figure out how to use react-intl-redux with TypeScript.

I've tried this:

import { combineReducers, AnyAction } from "redux";
import { intlReducer, IntlState } from "react-intl-redux";

export type AppState = {
  intl: IntlState;
};

export type AppAction = AnyAction;

export default combineReducers<AppState>({
  intl: intlReducer
});

But I've got a warning:

Argument of type '{ intl: (state: IntlState, action: IntlAction) => IntlState; }' is not assignable to parameter of type 'ReducersMapObject<AppState, AnyAction>'. Types of property 'intl' are incompatible. Type '(state: IntlState, action: IntlAction) => IntlState' is not assignable to type 'Reducer<IntlState, AnyAction>'. Types of parameters 'state' and 'state' are incompatible. Type 'IntlState | undefined' is not assignable to type 'IntlState'. Type 'undefined' is not assignable to type 'IntlState'. (alias) function intlReducer(state: IntlState, action: IntlAction): IntlState import intlReducer

Could you please help me out about this?

LKay commented 6 years ago

Make sure you have all typings up to date. The module does not ship with types definitions by itself so you have to use @types/react-intl-redux. They haven't been updated to exactly match version 2.0.0 but since there were no module API changes they still work fine. I'm using that in my projects and have no issues whatsoever.

mehmetnyarar commented 6 years ago

@LKay thanks for your response. I currently have:


"redux": "^4.0.0",
"react-redux": "^5.0.7",
"react-intl-redux": "^2.0.0",
"@types/redux": "^3.6.0",
"@types/react-redux": "^6.0.3",
"@types/react-intl-redux": "^0.1.10",

Would you mind sharing your code as an example?