react-i18next react-redux和TypeScript

时间:2018-07-05 14:44:31

标签: reactjs typescript redux react-redux i18next

所以...我必须使用TypeScript对i18n转换的组件进行redux连接。问题在于类型变得疯狂了!

interface Props extends InjectedTranslateProps {
  page: number;
}

interface StoreData {
  count: number;
}

const BookComponent = ({ page, count }: Props & StoreData) => {
...
}


const translatedComponent = translate(['books'])(BookComponent );

function mapStateToProps(state: Store): StoreData {
  return {
    count: state.count
  };
}

export default connect<StoreData, void, Props>(mapStateToProps)(translatedComponent);

它根本不想工作,并且出现此错误:

Argument of type 'ComponentClass<Pick<Props & InjectedTranslateProps, "page"> & TranslateHocProps>' is not assignable to parameter of type 'ComponentType<StoreData & DispatchProp<any> & Props>'.

Type 'ComponentClass<Pick<Props & InjectedTranslateProps, "page"> & TranslateHocProps>' is not assignable to type 'StatelessComponent<StoreData & DispatchProp<any> & Props>'.

Type 'ComponentClass<Pick<Props & InjectedTranslateProps, "page"> & TranslateHocProps>' provides no match for the signature '(props: StoreData & DispatchProp<any> & Props & { children?: ReactNode; }, context?: any): ReactElement<any> | null'.

const translatedForm: React.ComponentClass<Pick<Props & InjectedTranslateProps, "page"> & TranslateHocProps>

但是,如果我将Props更改为任何,该问题就会消失。

export default connect<StoreData, void, any>(mapStateToProps)(translatedComponent);

0 个答案:

没有答案