I have a very simple code in my app.tsx file:
/// <reference path="../modules/ReactSpa/Routing/Router.ts" />
import Router = ReactSpa.Routing.Router;
var router = new Router();
router.addParam('id', /([\d\-]+)/);
router.add('/articles/:id', 'Article');
console.log(router.find('/articles/1234'));
My tsconfig.json file:
{
"compilerOptions": {
"module": "umd",
"sourceMap": true,
"diagnostics": true,
"jsx": "react",
"out": "public/assets/scripts/compiled/app.js"
},
"files": [
"dev-files/scripts/applications/app.tsx"
]
}
Run compiling:
tsc
All work great! Now a want to include external library, React for example.
npm install react --save
npm install react-dom --save
tsd install react --save
tsd install react-dom --save
Change app.tsx file:
/// <reference path="../modules/ReactSpa/Routing/Router.ts" />
/// <reference path="../../../typings/react/react.d.ts" />
/// <reference path="../../../typings/react/react-dom.d.ts" />
import Router = ReactSpa.Routing.Router;
import React = __React;
import ReactDOM = __React.__DOM;
var router = new Router();
router.addParam('id', /([\d\-]+)/);
router.add('/articles/:id', 'Article');
console.log(router.find('/articles/1234'));
interface HelloWorldProps {
name: string;
}
var HelloMessage = React.createClass<HelloWorldProps, any>({
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
ReactDOM.render(<HelloMessage name="John" />, document.getElementById('hello'));
It compiles without any errors, but compiled file does not contain source code of React - only code of my libraries and code of app.tsx file.
I tried change import like this:
import React = require('react');
import ReactDOM = require('react-dom');
In this case compiled file contains only code of my libraries, even without code of app.tsx...
Bu the way, my modules defined like this:
namespace ReactSpa.Routing {
export class Router {
// ...
I read official docs, many articles, and themes at stackoverflow.com, but I just can not do this...
import React = require('react');. Can you please clarify further?React = __React;- app, withimport React = require('react');- app-with-import.