![](/img/trans.png)
[英]TS2339: Property 'focus' does not exist on type '{}'. with React typescript
[英]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);
我閱讀了此答案,並嘗試將StateProps
, DispatchProps
和OwnProps
但仍然會出現此錯誤。 如何解決此錯誤?
[編輯]我收到來自其父級的queryType
和query
(這些是強制性道具):
我的withContextId
出現問題。 顯然withContextId
是用JS編寫的,沒有任何類型。
刪除compose
並做以下事情幫助我解決了這個問題。 一個擁有更多typescript
知識的人可以掌握它,並讓我理解,因為我仍然是新手。
export default connect<StateProps, DispatchProps, OwnProps>(
mapStateToProps, mapDispatchToProps
)(withContextId(ContentContainer));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.