APSL / redux-i18n

A simple and powerful package for translate your react applications using react-redux.
MIT License
233 stars 52 forks source link

Reducer TypeScript definitition for combineReducers #115

Open jeroenlandheer opened 4 years ago

jeroenlandheer commented 4 years ago

I'm having some issues here to get the i18SnState reducer to get into my combineReducers() function. TypeScript complains that the type is not compatible with Reducer<IreduxI18nState> because of the state parameter not accepting undefined in the definition.

My workaround is this line of code:

export const reducer: Reducer<IreduxI18nState> = (state: IreduxI18nState | undefined, incomingAction: Action): IreduxI18nState => i18nState(state, incomingAction);

I think (not 100% sure) this can be solved by changing the signature of the this line in index.d.ts:

export function i18nState(state: IreduxI18nState, action: Action): IreduxI18nState

to

export function i18nState(state: IreduxI18nState | undefined, action: Action): IreduxI18nState
wijnbladh commented 4 years ago

Additionally, it would seem that this:

  export interface IGetTranslateFunctionResponse {
      (textKey: string, params?: string[], comment?: string): string;
  }

should be like this, or something:

  export interface IGetTranslateFunctionResponse {
      (textKey: string, params?: { [key: string]: string }, comment?: string): string;
  }

(based on looking at the source code)

JosephBrooksbank commented 3 years ago

Any updates on this? index.d.ts still appears to be incorrect, at least with regards to IGetTranslateFunctionResponse.