Emixam23
Emixam23

Reputation: 3964

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 !

Upvotes: 3

Views: 9804

Answers (1)

trydis
trydis

Reputation: 3925

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

Upvotes: 3

Related Questions