簡體   English   中英

Angular 2編譯器(ngc)是否可以與Typescript定義文件一起使用?

[英]Does the Angular 2 compiler (ngc) work with Typescript definition files?

構建針對Windows 10 UWP的Ionic 2應用程序。 在我的整個代碼中,我像這樣直接訪問winrt API

var localStorage = Windows.Storage.ApplicationData.current.localStorage;

使用tsc進行編譯是可行的,但是當我使用ngc編譯應用程序時,它將引發錯誤Cannot find namespace 'Windows'

顯然,Angular AOT不會對winrt Api有所了解,因為它不在UWP上下文中運行,但是我認為這就是Typescript定義文件的用途。

但是,如何解決此問題? 我認為也許包括Typescript定義文件都可以解決此問題,但是Typescript可以很好地編譯。

這是我的項目Types.json文件

{
  "dependencies": {},
  "devDependencies": {},
  "globalDependencies": {
    "winrt": "registry:dt/winrt#0.0.0+20160622234326",
    "angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459",
    "core-js": "registry:dt/core-js#0.0.0+20160725163759",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "node": "registry:dt/node#6.0.0+20160831021119",
    "selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654"
  }
}

我想出了如何使這項工作。 基本上,您需要手動在Typescript文件的頂部添加引用,然后進行編譯。 希望這對某人有幫助。

/// <reference path="../../typings/globals/winrt/index.d.ts" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM