I am trying to create a workflow where I can write React modules using TypeScript and automatically compile in JavaScript via Gulp.js. I am using TypeScript 1.6.2, gulp-react and gulp-typescript.
Now my .tsx file looks like this:
/// <reference path="../../../../typings/react/react.d.ts" /> import React = __React; interface HelloWorldProps { name: string; } var HelloMessage = React.createClass<HelloWorldProps, any>({ render: function() { return <div>Hello {this.props.name}</div>; } }); React.render(<HelloMessage name="helloooo" />, document.getElementById('test'));
My problem in this line: import React = __React;
When I leave this, I get an error
error TS2304: Cannot find the name "React".
when compiling .tsx to .js (but it still compiles in JSX and I can use the output). When I insert it, I can compile without errors, but when I try to use the file inside the browser, I get an Uncaught ReferenceError: __React is not defined , of course.
This is what my gulptask looks like:
gulp.task('gui-tsx', function () { var tsResult = gulp.src(config.guiSrcPath + 'tsx/app.tsx') .pipe(ts({ jsx: 'react' })); return tsResult.js.pipe(gulp.dest(config.guiSrcPath + 'jsx')); });
Is there a workaround for this? Or am I missing something here?
javascript reactjs typescript gulp
Felix hagspiel
source share