2016-05-27 8 views
1

Ich versuche, mit TypeScript und React zu beginnen. Da in JavaScript Reagieren geschrieben wird, installiere ich es npmWie zu installieren/zu importieren Reagieren in TypeScript

npm install --save react 

mit brauche ich Typdefinitionen für React. Also habe ich versucht

$ 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 

Ich lief typings search react und fand

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

Daher habe ich explizit angegeben, die Quelle

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

ich global Reagieren installieren kann

typings install dt~react --save --global 

aber Atom klagt noch wenn ich versuche,

import React from 'react' 

React zu importieren Wie Sie installieren Reagieren oder Typoskript so konfigurieren, dass Sie reagieren in Typoskript importieren kann?

Antwort

7

Die React-Lib hat keinen Standard-Export. Wenn Sie es also an import React fragen, sucht es nach einem Standardexport in dieser Bibliothek. Leider existiert es nicht. Importieren Sie stattdessen den gesamten Inhalt und den Namespace auf diese Weise:

import * as React from 'react';