简体   繁体   English

如何解决打字稿错误 TS2339:“IntrinsicAttributes & …”类型上不存在“XXX”属性?

[英]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将期望收到一个名为testprop 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.

相关问题 如何解决错误“TS2339:&#39;JQuery 类型上不存在属性&#39;仪表&#39;<HTMLElement> &#39;。” - How do I resolve error "TS2339: Property 'gauge' does not exist on type 'JQuery<HTMLElement>'." 错误TS2339:类型“ HTMLElement”上不存在属性“ imageID” - error TS2339: Property 'imageID' does not exist on type 'HTMLElement' 错误TS2339:类型“字符串”上不存在属性“默认”。** - Error TS2339: Property 'Default' does not exist on type 'string'.** 错误 TS2339:类型“CustomerTransfert[]”上不存在属性“num” - error TS2339: Property 'num' does not exist on type 'CustomerTransfert[]' 错误TS2339:类型“ {}”上不存在属性“ forEach” - error TS2339: Property 'forEach' does not exist on type '{}' 错误TS2339:类型“ HTMLElement”上不存在属性“名称” - error TS2339: Property 'name' does not exist on type 'HTMLElement' 错误 TS2339:“温度”类型上不存在属性“摄氏度” - error TS2339: Property 'celsius' does not exist on type 'Temperature' 错误 TS2339:“特殊 []”类型上不存在属性“默认” - Error TS2339: Property 'default' does not exist on type 'Special[]' 如何在Typescript中为其子项设置功能道具类型? TS2339类型上不存在“孩子”属性 - How to set function props type for its child in Typescript? Property 'children' does not exist on type TS2339 TypeScript 错误:属性“scrollIntoView”在类型“never”上不存在。 TS2339 - TypeScript error: Property 'scrollIntoView' does not exist on type 'never'. TS2339
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM