最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览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.

发布评论

评论列表(0)

  1. 暂无评论