具有第三部分库和Angular-CLI的IntelliSense



在使用angular2-cli创建的项目中,我需要使用某些第三部分的JavaScript库,这些库应在全局JavaScript范围中可用(例如,来自Tween.js库中的Tween名称空间)。

相应地到Angular-CLI指南以安装JS库作为Global我使用NPM安装,并在Angular-Cli.json文件的"脚本"数组中添加库脚本。

"scripts": [
    "../node_modules/tween.js/src/Tween.js"
  ],

要在我声明的角度组件中使用全局互二个命名空间在文件开头的常数变量,如以下内容:

import { Component, OnInit } from '@angular/core';
declare const TWEEN: any;
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
  title = 'app works!';
  constructor() { }
  ngOnInit() {
    let tween = new TWEEN.Tween({x: 0}).to({x: 1}, 2000);
    // .. 
  }
}

这有效,但问题是我不会以这种方式获得第三部分库中的任何Intellisense(我正在使用WebStorm)。我有什么能做到的,以使IntelliSense起作用?还是有更好的方法在Angular 2工作流程中导入第三部分JavaScript库?

您永远不会以这种方式获得Intellisense,因为您将文件顶部定义为"任何",没有Intellisense )。

您应该看这篇文章:https://weblog.west-wind.com/posts/2016/sep/12/external-javascript-depparies-in-y-typescript-and-angular-2
这几乎告诉您,您要么在库本身中打字,因此安装时可以免费出现,或者只是在没有打字的情况下工作。

如果您要与根本没有打字的库一起工作,则可能需要考虑自己创建打字。

最新更新