我想製作一個工作流程,我可以使用TypeScript編寫React模塊,並通過Gulp.js自動編譯爲JavaScript。我正在使用TypeScript 1.6.2,gulp-react和gulp-typingcript。TypeScript,React和Gulp.js - 定義反應
我.tsx
文件現在看起來是這樣的:
/// <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'));
我的問題是這樣的一行:import React = __React;
當我離開它,我得到的錯誤
錯誤TS2304:不能找到名字'React'。'
當編譯.tsx
到.js
(但它仍然編譯爲JSX,我可以使用輸出)。當我把它放入時,我可以毫無錯誤地進行編譯,但是當我嘗試在瀏覽器中使用該文件時,當然會得到Uncaught ReferenceError: __React is not defined
。
這是我gulptask看起來像:
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'));
});
是否有解決方法嗎?或者我在這裏錯過了什麼?
是否有使用'typings',而不是'tsd'任何類似的解決方案? – jpierson