2016-05-27 12 views
1

TypeScriptReactを使い始めます。リアクトはJavaScriptで書かれているので、私は私が反応のための型定義を必要とするnpmインストール/インポート方法React in TypeScript

npm install --save react 

を使用してインストールします。だから私は、私はtypings search reactを実行し、

NAME SOURCE HOMEPAGE       DESCRIPTION VERSIONS UPDATED 
react dt  http://facebook.github.io/react/    2   2016-05-26T13:46:01.000Z 

そこで見つけ

$ 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 

みました、私は明示的に私が反応インストールすることができます

$ typings i dt~react --save 
typings ERR! message Attempted to compile "react" as an external module, but it looks like a global module. 

ソースを指定したグローバル

typings install dt~react --save --global 

が、012私はあなたが反応インストールまたはインポート活字体で反応できるように、活字体を構成するにはどうすればよい

import React from 'react' 

を反応させるのインポートしようとするとはまだを不平を言いますか?

答えて

7

リアクションライブラリにはデフォルトの書き出しがありません。だから、import Reactにそれを聞くと、そのライブラリのデフォルトのエクスポートを探します。残念ながら、それは存在しません。代わりに、この方法でコンテンツと名前空間全体をインポートしてください:

import * as React from 'react';