Reactjs 如何在TypeScript中安装/导入React

Reactjs 如何在TypeScript中安装/导入React,reactjs,typescript,atom-editor,typescript-typings,Reactjs,Typescript,Atom Editor,Typescript Typings,我试着开始和。因为React是用JavaScript编写的,所以我使用 我需要React的类型定义。所以我试过了 $ typings install react --save typings ERR! message Unable to find "react" ("npm") in the registry. Did you want to try searching another source? Also, if you want contribute these typings, ple

我试着开始和。因为React是用JavaScript编写的,所以我使用

我需要React的类型定义。所以我试过了

$ typings install react --save
typings ERR! message Unable to find "react" ("npm") in the registry. Did you want to try searching another source? Also, if you want contribute these typings, please help us: https://github.com/typings/registry
typings ERR! caused by https://api.typings.org/entries/npm/react/versions/latest responded with 404, expected it to equal 200
我运行了
打字搜索react
并找到了

NAME   SOURCE  HOMEPAGE                          DESCRIPTION  VERSIONS  UPDATED
react  dt      http://facebook.github.io/react/               2         2016-05-26T13:46:01.000Z
因此,我明确指定了源代码

$ typings i dt~react --save
typings ERR! message Attempted to compile "react" as an external module, but it looks like a global module.
我可以在全球范围内安装React

typings install dt~react --save --global
但是当我尝试导入react时,仍然抱怨
找不到模块“react”

import React from 'react'

如何安装React或配置TypeScript,以便在TypeScript中导入React?

React库没有默认导出。因此,当您要求它
导入React
时,它会在该库中查找默认导出。不幸的是,它并不存在。而是以以下方式导入整个内容和命名空间:

import * as React from 'react';

React库没有默认导出。因此,当您要求它
导入React
时,它会在该库中查找默认导出。不幸的是,它并不存在。而是以以下方式导入整个内容和命名空间:

import * as React from 'react';