在加載應用程序之前,您需要手動添加一些文件到您的index.html或您使用的其他任何文件(即cshtml Razor模板)。它應該看起來像這樣
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="~/lib/core-js/client/shim.min.js"></script>
<script src="~/lib/zone.js/dist/zone.js"></script>
<script src="~/lib/reflect-metadata/Reflect.js"></script>
<script src="~/lib/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="~/app/system.config.js" asp-append-version="true"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
順序很重要。這是運行應用程序所必需的。
如果您在Visual Studio中遇到錯誤,那麼您可能會錯過所需的「類型」。
到現在爲止,你需要安裝分型(從的NodeJS頁面安裝的NodeJS,使其在shell/PowerShell中/命令行全局可用),然後運行npm install typings -g
安裝分型,並切換到文件夾,你的項目和運行typings install dt~node
,typings install dt~jasmine
和typings install dt~core-js
。這會在typings
文件夾中安裝輸入文件。
隨着打字稿2.0有通過NPM瓦特/安裝類型定義Ó需要分型的(參見打字稿2.0公告here),通過運行下面的命令的更新:npm install -s @types/<nameofthelibrary>
,即npm install -s @types/node
,npm install -s @types/jasmine
和npm install -s @types/core-js
。
的require
方法在node
包/分型定義,如在節點分型內的index.d.ts文件中declare var require: NodeRequire;
看出。