簡體   English   中英

Typescript TS2339:在Typescript + React + Redux應用程序中,類型'IntrinsicAttributes'上不存在屬性'queryType'嗎?

[英]Typescript TS2339: Property 'queryType' does not exist on type 'IntrinsicAttributes' in Typescript + React + Redux app?

我在React + Redux應用程序中使用Typescript。 我的組件之一利用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);

我閱讀了答案,並嘗試將StatePropsDispatchPropsOwnProps但仍然會出現此錯誤。 如何解決此錯誤?

[編輯]我收到來自其父級的queryTypequery (這些是強制性道具):

我的withContextId出現問題。 顯然withContextId是用JS編寫的,沒有任何類型。

刪除compose並做以下事情幫助我解決了這個問題。 一個擁有更多typescript知識的人可以掌握它,並讓我理解,因為我仍然是新手。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM