1
我對TypeScript開發有點新,但設法很快就掌握了它。 但是,我發現自己對使用所有這些模塊加載器,編譯器,設置以及沒有設置項目感到沮喪。如何在Visual Studio中設置帶有React的TypeScript
我想在Visual Studio 2017中設置一個帶有React的TypeScript工作環境,但無濟於事。我已經試過如下:
MyTestComponent.tsx
/// <reference path="../typings/react/index.d.ts"/>
interface IProps {
name: string
}
class MyTestComponent extends React.Component<IProps, {}> {
render() {
console.log("rendering component");
return <span>{this.props.name}</span>;
}
}
App.ts
/// <reference path="TsImports.ts"/>
class App {
constructor() {
console.log("app started");
React.createElement(MyTestComponent,
{ name: "somename" },
document.getElementById("someid"));
}
}
的index.html
<div id="someid"></div>
<script src="~/Scripts/app.js"></script>
<script type="text/javascript">
var app = new App();
</script>
我在控制檯中獲得「應用程序啓動」,但沒有渲染元素。我也沒有得到任何控制檯錯誤。
我也試過VS碼中的打字稿網站的官方教程,它的工作原理。但是我無法弄清楚Webpack
在整個過程中的作用。有人可以請一些細節解釋如何設置,或至少指出我在某些資源。謝謝!