Sandeep Thomas
Sandeep Thomas

Reputation: 4727

Adding typescript to an existing react App

I am trying to add/convert my existing react app (Almost empty) into typescript instead of JS. So based on some tutorials I have added a tsconfig.json into my project root with below contents

{
    "compilerOptions": {
      "outDir": "./dist/",
      "noImplicitAny": true,
      "module": "es6",
      "target": "es5",
      "jsx": "react",
      "allowJs": true,
      "moduleResolution": "node",
    }
  }

Then I installed typescript

npm install -g typescript

So what I did next is renamed my index.js as index.tsx and app.js and app.tsx and there is simple container component which I renamed to tsx as well.

But when I run the application by npm start its showing below error

enter image description here

I didnt get what I missed or what I did wrong. Very new to React.

Upvotes: 0

Views: 628

Answers (1)

Sachila Ranawaka
Sachila Ranawaka

Reputation: 41387

Install types for the react

npm i -D @types/react @types/react-dom 

Upvotes: 2

Related Questions