javascript - React Typescript - What's the difference between import @typesreact and import react - Stack Overflow

admin2025-04-20  0

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 !

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 !

Share Improve this question edited Oct 12, 2021 at 13:23 Emixam23 asked Sep 6, 2019 at 20:04 Emixam23Emixam23 3,9648 gold badges55 silver badges117 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745110322a285542.html

最新回复(0)