打字稿定制d.ts文件
问题描述:
我有我转换为打字稿的项目。我已经下载了最新的@types和我试图创建一个custom.d.ts文件。该文件看起来像这样至今:打字稿定制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不承认它吗?我使用的打字稿2.5.2和 “@类型/ jQuery的”: “^ 3.2.12” 谢谢。
答
的问题可能是,因为你的类型JQuery
,不jQuery
变量。
同样适用于JQueryStatic
(应为jQueryStatic
打字稿识别notific8
属性)