How to compile typescript with definition reactions

I am trying to write a typescript module that uses React.addons.update. However, I could not find a way to compile it.

I have a folder with the following files:

I run the following commands:

node <pathtotsc>\tsc -v
=> message TS6029: Version 1.3.0.0

node <pathtotsc>\tsc react.d.ts test.ts
=> test.ts(2,1): error TS2304: Cannot find name 'React'.

What am I missing? How to refer to the definition of reaction?

change

node <pathtotsc>\tsc test.ts
test.ts(2,1): error TS2304: Cannot find name 'React'.
+4
source share
3 answers

Relevant information can be found here . The trick is to “cancel” the explanation in order to understand how the definition file should be used.

, response.d.ts :

/// <reference path="react.d.ts"/>
import React = require("react/addons");
React.addons.update({}, {$set : "foo" });

, tsc, ( ). , , :

declare var React : AddonsExports

, , , update , .

+3

14 2016 , React 0.14.3 Typescript 1.6.2, d.ts Typescript React ReactDom ts .

tsd install react-global --save tsd update --save --overwrite

. , react.d.ts. , React .

react-global tsd.d.ts:

/// <reference path="react/react-dom.d.ts" /> /// <reference path="react/react-addons-create-fragment.d.ts" /> /// <reference path="react/react-addons-css-transition-group.d.ts" /> /// <reference path="react/react-addons-linked-state-mixin.d.ts" /> /// <reference path="react/react-addons-perf.d.ts" /> /// <reference path="react/react-addons-pure-render-mixin.d.ts" /> /// <reference path="react/react-addons-test-utils.d.ts" /> /// <reference path="react/react-addons-transition-group.d.ts" /> /// <reference path="react/react-addons-update.d.ts" /> /// <reference path="react/react-global.d.ts" />

+1

Alternatively, you can use a file react-addons.d.ts(available on NuGet or through a specifically typed file ).

/// <reference path="scripts/typings/react-addons/react-addons.d.ts" />

React.addons.update({}, { test: { $set: "foo" } });
0
source

All Articles