【问题标题】:Referencing external JS library in typescript在 typescript 中引用外部 JS 库
【发布时间】:2016-08-26 11:37:41
【问题描述】:

我想在我的类型脚本(.ts)文件中使用 Jquery 库,并且我使用 原子编辑器。

为了实现这一点,我遵循了以下步骤

  1. 由于我使用 atom 编辑器,所以安装了 apm install atom-typescript

  2. 由于 Jquery 是外部 JS 库,我已经下载了类型化定义 来自here 并将文件放在我的应用程序文件夹中

3 在我的 test.ts 文件中添加了对 jquery.d.ts 的引用

下面是test.ts代码

/// <reference path="./node_modules/jquery/dist/jquery.d.ts" />

export class test {
$("#testID").val("test"); // editor shows ERROR in this line , "parameter    declaration expected"
 }

请让我知道我错过了什么。

【问题讨论】:

    标签: typescript atom-editor


    【解决方案1】:

    最好不要复制粘贴定义文件,而是使用typings。打字为你处理了很多,例如。您不必考虑引用正确的路径。

    所以只需运行 typings inittypings install --save --global dt~jquery 就可以了。

    【讨论】:

      猜你喜欢
      • 2021-08-19
      • 2016-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-28
      • 2017-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多