0

I am familiar with React and I decided I will also learn how TypeScript is written so I can use React + Typescript together.

I created latest Vite React app but I have lot of problems with imports, I was trying searching it with google but couldn't find any really good answers.

Example:

import React, { JSX } from "react";
import TodoList from "./components/TodoList";

function App(): JSX.Element {
    const todos = [{id: 1, text: "Finish the course"}]
    return (
        <div>
            <h1>Hello world</h1>
            <TodoList items={todos}/>
        </div>
  )
}

export default App

On this simple code I get those errors:

  • Type 'Element' is missing the following properties from type 'ReactElement ': type, props, key
  • Property 'h1' does not exist on type 'JSX.IntrinsicElements'.

When I googled those errors all I found was to write in capital letters, but that couldn't work with HTML/JSX. I also tried : React.FN but taht also don't work.

3
  • You shouldn't import JSX from react, it is a global namespace
    – Florent M.
    Commented May 17, 2023 at 9:50
  • what is the extension of your file ? Is is App.tsx ? Did you use the vite template react-ts ? Commented May 17, 2023 at 9:53
  • @FlorentM. Yes I understand, I just tried it if it will fix it. @OlivierBoissé I used Vite template, I have all tsx files, I didn't touch tsconfig.json except for "allowSyntheticDefaultImports": true Commented May 17, 2023 at 10:13

1 Answer 1

0

I found out what was the main problem.

  1. It was that my IDE (WebStorm) was reading typescript module from another project (it was not the same version).

  2. Also second thing is that React.FC is not working the same as the tutorial I watched. Also JSX.Element is depreceted.

So I used React.ReactElement and now it is working. Thanks to: Stack Overflow Question/Answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.