Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Typescript - What's the difference between import @types/react and import react

I am a beginner with react (even tho I did some ReactJs already) and I am today trying to create a simple app using TypeScript (instead of pure Javascript).

However, when running npm start, I found an issue that I understand, but I can't understand why it is an issue.

Let say we have this code (main.tsx):

import * as React from 'react';

Can you explain to me clearly what is the difference with

import * as React from '@types/react';

In my package.json I have "@types/react": "^16.9.2" and I don't have react, so the issue is quite logic that the package couldn't be found. But then what's the difference between these two imports?

Also, I can't even import @types/react, I can only install it

Thanks !

like image 855
Emixam23 Avatar asked May 15 '26 05:05

Emixam23


1 Answers

The ones with @types prefix are type declaration packages, more info here.

like image 162
trydis Avatar answered May 16 '26 18:05

trydis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!