[英]How to resolve typescript error TS2339: Property 'XXX' does not exist on type 'IntrinsicAttributes & …?
In my typescript/reactjs app I am trying to pass in a property called test like this, this is part of the index.tsx:在我的 typescript/reactjs 应用程序中,我试图传入一个名为 test 的属性,这是 index.tsx 的一部分:
ReactDOM.render(
<Provider store={getStore()}>
<BrowserRouter>
<App test={1} />
</BrowserRouter>
</Provider>,
document.getElementById('content')
);
In my app.tsx I have:在我的 app.tsx 中,我有:
export class App extends React.Component<any,{}>{
constructor(props){
super(props);
}
render(){
..
}
}
When I run the app I get this error:当我运行应用程序时,我收到此错误:
ERROR in ./src/index.tsx
(24,12): error TS2339: Property 'test' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<{}, ComponentState>> & Readonly<{ childr...'.
How can I make sure this error is resolved or how can I pass in a property on my App component?我怎样才能确保这个错误得到解决,或者我怎样才能在我的 App 组件上传递一个属性?
这似乎是 ReactRedux connect 和 Typescript 的一个更大问题,在寻找可行的解决方案时出现了这样的问题,因此我们的团队正在认真考虑在我们的 React 应用程序中删除 Typescript。
You need to define an interface
for your component's Props
and pass that as a type argument to React.Component
.您需要为组件的
Props
定义一个interface
,并将其作为类型参数传递给React.Component
。 This way, App
will expect to receive a prop
called test
.这样,
App
将期望收到一个名为test
的prop
。 For example:例如:
interface Props {
test: <whatever type test is>
}
class App extends React.Component<Props, {}> {
// your component code
}
There is some notorious discussion around connect
with TS.有一些关于
connect
TS 的臭名昭著的讨论。 You may check out this SO post for help: Typescript + React/Redux: Property "XXX" does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes您可以查看此 SO 帖子以获取帮助: Typescript + React/Redux: Property "XXX" does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes
确保组件名称以大写字母开头
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.