Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript Error: TS2339: Property 'span' does not exist on type 'JSX.IntrinsicElements'

All of a sudden my react typescript project has started rejecting <span> tags with

TS2339: Property <span> does not exist on type 'JSX.IntrinsicElements'

Every other tag is absolutely fine, but <span>s any where in my .tsx files throw this error.

Can anyone advise?

like image 658
RNDThoughts Avatar asked Dec 07 '17 11:12

RNDThoughts


People also ask

Does not exist on type JSX IntrinsicElements typescript?

The error "Property does not exist on type 'JSX. IntrinsicElements'" occurs when a component's name starts with a lowercase letter. To solve the error, make sure to always start component names with a capital letter, install the types for React and restart your dev server.

What is JSX intrinsic elements?

Type Checking For React, intrinsic elements are emitted as strings ( React. createElement("div") ), whereas a component you've created is not ( React. createElement(MyComponent) ). The types of the attributes being passed in the JSX element should be looked up differently.

Does not have any construct or call signatures?

The error "JSX element type does not have any construct or call signatures" occurs when we try to pass an element or a react component as props to another component but type the prop incorrectly. To solve the error, use the React. ElementType type.

How to fix typescript error ts2339?

error TS2339: Property 'userLanguage' does not exist on type 'Navigator'. Solution: Check the error message for the correct file and line. Currently typescript does not have userLanguage as a property (tested with typescript up to 2.7.1), although it should already be fixed according to this issue.

How to fix ts2339 “property ‘x’ does not exist on type ‘Y’” with typescript?

To fix the error “TS2339: Property ‘x’ does not exist on type ‘Y’” with TypeScript, we should make sure the properties are listed in the interface that’s set as the type of the object. interface Images { main: string; [key: string]: string; } const getMainImageUrl = (images: Images): string => { return images.main; };

Is it possible to get about-me property in typescript?

Property 'about-me' does not exist on type 'JSX.IntrinsicElements'. Remember: "item" is not valid in TypeScript, you must declare as "Item", UpperCase the first letter!

Does not exist on type'MyClass'property?

When compiled/transpiled through TypeScript it generates error TS2339: Property 'myclassvar' does not exist on type 'MyClass'. If the above code snippet is valid ES6 then TypeScript should not generate the error. The generated javascript it valid. It's just that the error scares the developers trying to use ES6 without typings.


2 Answers

I had the same problem but for me, it was the p element. The reason for the error was that I refactored a p element to h3 for instance and VSCode changed also the type definition.

As you pointed out cleaning the node_modules and doing a fresh npm install does the trick.

Just wanted to point out what could cause the problem.

like image 158
datoml Avatar answered Oct 11 '22 20:10

datoml


Can anyone advise?

  • Make sure you have import * as React from 'react' in your file
  • Update types for react npm install @types/react
like image 31
basarat Avatar answered Oct 11 '22 19:10

basarat