我有一个项目,我正在转换为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>'.
我已经尝试将声明行移动到app文件中,但我仍然得到相同的错误?有人知道为什么Typescript没有认识到它吗?我正在使用typescript 2.5.2和&#34; @ types / jquery&#34;:&#34; ^ 3.2.12&#34;感谢。
答案 0 :(得分:0)
问题可能是,因为您有JQuery
类型的变量,而不是jQuery
。
同样适用于JQueryStatic
(应用jQueryStatic
对于Typescript来识别notific8
属性)