javascript - React Typescript 属性在类型/IntrinsicAttributes 和 IntrinsicClassAttributes 上不存在

标签 javascript reactjs typescript

TypeScript 的新手,感觉它应该非常简单,但我对语法不太满意!

非常简单的组件:

import * as React from "react";
import ControlArea from "./ControlArea";

interface IControlAreaProps {
  welcome?: any;
}

export class Layout extends React.Component<IControlAreaProps> {
  public render() {
    return (
        <ControlArea welcome="This is the control area"/>
    );
  }
}

我收到 TS 错误 Property 'welcome' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<ControlArea> & Readonly<{ children?: ReactNode; }>...'.

任何指向正确方向的观点都将不胜感激。

最佳答案

你在这里的错误是你将界面添加到 Layout 组件,而你应该将它们添加到 ControlArea 组件

interface IControlAreaProps {
  welcome?: any
}

export default class ControlArea extends React.Component<IControlAreaProps> {
  // Your ControlArea code
}

关于javascript - React Typescript 属性在类型/IntrinsicAttributes 和 IntrinsicClassAttributes 上不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48890795/

相关文章:

javascript - 我应该使用什么 JavaScript 模式从原型(prototype)方法访问私有(private)方法?

javascript - 在 AJAX js 调用中动态分配值

reactjs - 将 Favicon.ico 添加到 Contentful 或 Gatsby 网站

javascript - typescript 错误: "Element implicitly has an ' any' type because expression of type 'any' can't be used to index type

javascript - Angular2 创建组件

java - 检索单个操作的 WSDL

javascript - 当我在 Angular 6 中将其设置为可编辑内容时,如何将焦点设置在该元素上?

javascript - 函数 simpleNameGame 未定义

javascript - 使用 react-router-redux 访问参数

typescript - 以嵌套方式将界面中的所有字段设为只读