typescript JSX 元素类型没有任何构造或调用签名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37675920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:33:33  来源:igfitidea点击:

JSX element type does not have any construct or call signatures

reactjstypescriptreact-css-modules

提问by Richard

I'm using this simple React element on the left as my root element on the page in the right.

我在左侧使用这个简单的 React 元素作为右侧页面上的根元素。

How do I fix the error shown?

如何修复显示的错误?

enter image description here

在此处输入图片说明

回答by Richard

This hacky typecast makes the error go away, though I don't understand it at all:

这个 hacky typecast 使错误消失了,尽管我根本不明白:

const App: any = require('./components/views/app/app');

const App: any = require('./components/views/app/app');

回答by vorillaz

How about:

怎么样:

class App extends React.Component<any, any> {
    render() {
        return <div>foo</div>;
    }
}

回答by Michael Frost Billing

React expects a React.StatelessComponent from the imported App in mainScreenHelper.tsx This means that you need to provide that interface in App

React 期望从 mainScreenHelper.tsx 中导入的 App 中获得 React.StatelessComponent 这意味着您需要在 App 中提供该接口

interface IProps {}
const App : React.StatelessComponent<IProps> = () => (
   <div></div>
);