20

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

How do I fix the error shown?

enter image description here

Richard
  • 14,798
  • 21
  • 70
  • 103
  • 1
    Your code looks correct to me; which version of Typescript are you using? It seems it's [1.8](https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#stateless-function-components-in-react) that provided more support with React stateless function components. – Johnny Magrippis Jun 07 '16 at 10:00
  • Yup, latest version of TS and Typings and definitions. – Richard Jun 07 '16 at 11:14
  • I have the same problem. Doesn't seem to support stateless components. ts 1.8.10. – ieugen Aug 22 '16 at 20:37
  • Do you still get the message when you default export the App directly, without the cssModules HOC? Do you still have the problem when changing the filename of app.tsx, and you do not get an error message about thhe unresolveable require? – Fabian S Jan 29 '19 at 14:09

3 Answers3

2

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

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

mawburn
  • 2,232
  • 4
  • 29
  • 48
Richard
  • 14,798
  • 21
  • 70
  • 103
  • 4
    Here you are casting `App` as an `Any` type and bypassing the type system. The Typescript errors went away because now you are effectively just using Javascript. – Connor Finn McKelvey Nov 04 '17 at 22:17
1

How about:

class App extends React.Component<any, any> {
    render() {
        return <div>foo</div>;
    }
}
vorillaz
  • 6,098
  • 2
  • 30
  • 46
  • Thanks, but I don't see how that helps. The app.ts file is returning `cssModules(App, css)`, not the function App in the app.ts file. – Richard Jun 07 '16 at 11:15
0

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

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