简体   繁体   中英

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

Building an Ionic 2 application that targets Windows 10 UWP. Throughout my code, I access the winrt API's directly, like this

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

Compiling with tsc works, but when I compile the application with the ngc, it throws an error Cannot find namespace 'Windows'

Obviously, the Angular AOT wouldn't know anything about the winrt Api's because it's not running within the context of a UWP, but I thought that's what Typescript definition files were for.

But how do I work around this issue? I thought that perhaps including the Typescript definition file would have solved this, but Typescript compiles fine.

Here's my projects typings.json file

{
  "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"
  }
}

I figured out how to make this work. Basically, you manually need to add a reference at the top of your Typescript file, and then compile. Hope this helps someone.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM