【问题标题】:Typescript custom d.ts files打字稿自定义 d.ts 文件
【发布时间】:2018-03-04 10:36:27
【问题描述】:

我有一个项目要转换为 Typescript。我已经下载了最新的@types 并试图创建一个 custom.d.ts 文件。到目前为止,该文件看起来像这样:

/// <reference path="../../../node_modules/@types/jquery/index.d.ts"/>

interface jQuery{
    iCheck(): JQuery;
    bootstrapSwitch(): JQuery;
}

interface jQueryStatic{
    notific8(): JQuery;
}

declare var notific8: JQueryStatic;
declare var isCheck: JQuery;
declare var bootstrapSwitch: JQuery;

在我试图使用定义的文件中,我使用它来引用它

/// <reference path="../utility/custom.d.ts" />

Visual Studio 识别出路径是正确的,但是当我将鼠标悬停在实现它的代码上时,我得到:

[ts] Property 'notific8' does not exist on type 'JQueryStatic<HTMLElement>'

[ts] Property 'iCheck' does not exist on type 'JQuery<HTMLElement>'.
[ts] Property 'bootstrapSwitch' does not exist on type 'JQuery<HTMLElement>'.

我尝试将声明行移动到应用程序文件中,但我仍然遇到同样的错误?有人知道为什么 Typescript 无法识别它吗?我正在使用 typescript 2.5.2 和 "@types/jquery": "^3.2.12" 谢谢。

【问题讨论】:

    标签: jquery typescript types


    【解决方案1】:

    问题可能是,因为您有JQuery 类型的变量,而不是jQuery

    同样适用于JQueryStatic(应该是jQueryStatic,以便Typescript 识别notific8 属性)

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2019-01-02
      • 1970-01-01
      • 2021-09-13
      • 2017-05-07
      • 2020-04-30
      • 2020-09-08
      • 2018-09-13
      • 2016-09-02
      相关资源
      最近更新 更多