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

4
  • 1
    Your code looks correct to me; which version of Typescript are you using? It seems it's 1.8 that provided more support with React stateless function components. Commented Jun 7, 2016 at 10:00
  • Yup, latest version of TS and Typings and definitions. Commented Jun 7, 2016 at 11:14
  • I have the same problem. Doesn't seem to support stateless components. ts 1.8.10. Commented Aug 22, 2016 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? Commented Jan 29, 2019 at 14:09

3 Answers 3

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');

Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

How about:

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

1 Comment

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.
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>
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.