TypeScript 3.4-连接的组件错误类型

时间:2019-04-05 09:17:11

标签: reactjs typescript

其他人在更新到TypeScript 3.4时遇到意外行为吗?

我的组件现在无法识别从connect函数传递的道具。

import React, { SFC } from "react";
import { connect } from "react-redux";
import { Dispatch } from "../../types";
import * as actions from "../actions";

interface IOwnProps {
  readonly id: string;
  readonly name: string;
  readonly className?: string;
}

type DispatchProps = ReturnType<typeof mapDispatchToProps>;
type Props = IOwnProps & DispatchProps;

export const Collapsable: SFC<Props> = (props) => (
  <div onClick={props.toggle} className={props.className}>
    {props.children}
  </div>
);

function mapDispatchToProps(dispatch: Dispatch, ownProps: IOwnProps) {
  return {
    toggle: () => dispatch(actions.toggle(ownProps.name, ownProps.id)),
  };
}

export default connect(
  null,
  mapDispatchToProps,
)(Collapsable);

使用TypeScript 3.3.4可以正确选择“ id”,“ name”,“ className”,但是使用3.4时,也可以选择“ toggle”

TypeScript 3.4 component

TypeScript 3.3可以正确解析它 enter image description here

0 个答案:

没有答案