Typescript TS2339:在Typescript + React + Redux应用程序中,类型'IntrinsicAttributes'上不存在属性'queryType'吗?

时间:2018-11-06 05:33:42

标签: reactjs typescript react-redux

我在我的react + redux应用程序中使用打字稿。我的组件之一利用了react-redux的连接。代码是这样的:

import * as React from 'react';
import * as Redux from 'redux'
import compose from 'recompose/compose';
import {
  connect,
} from 'react-redux';

import withContextId from '../../../../../app/containers/pageTab/contexts/withContextId';

import {
  fetchContent,
} from '../../actions/workspaceActions';

import { HomePageQuery } from '../../interfaces';

interface Props extends StateProps, DispatchProps {
  queryType: string,
  query: string,
  contextId: string,
}

interface OwnProps {
  queryType: string,
  query: string,
  contextId: string,
}

class ContentContainer extends React.PureComponent<Props, {}> {
  componentDidMount() {
    const { props } = this;

    props.fetchContent(props.queryType, props.query, props.contextId);
  }

  render() {
    return (
      <div>
        {'Tiles Container'}
      </div>
    );
  }
}

interface DispatchProps {
  fetchContent: (query: string, queryType: string, contextId: string) => void
}

function mapDispatchToProps(dispatch: Redux.Dispatch<any>): DispatchProps {
  return {
    fetchContent: (query: string, queryType: string, contextId: string) => {
      dispatch(fetchContent(query, queryType, contextId))
    }
  };
}

interface StateProps {
}

function mapStateToProps(state: any): StateProps {
  return {};
}

export default compose(
  withContextId,
  connect<StateProps, DispatchProps, OwnProps>(mapStateToProps, mapDispatchToProps),
)(ContentContainer);

我阅读了this的答案,并尝试将StatePropsDispatchPropsOwnProps分开,但仍然会出现此错误。如何解决此错误?

[编辑] 我从其父母那里收到queryTypequery的身份(这些都是必不可少的道具):

1 个答案:

答案 0 :(得分:0)

我在临时withContextId上遇到了问题。显然withContextId是用JS编写的,没有任何类型。

删除compose并执行以下操作可帮助我解决问题。一个拥有更多typescript知识的人可以掌握它,并让我理解,因为我仍然是新手。

export default connect<StateProps, DispatchProps, OwnProps>(
  mapStateToProps, mapDispatchToProps
)(withContextId(ContentContainer));