加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

typescript – 后续变量声明必须具有相同的类型.变量’$’必须是

发布时间:2020-12-17 07:28:15 所属栏目:安全 来源:网络整理
导读:我有一个非常简单的文件: /// reference path="../typings/browser/ambient/jquery/jquery" /import {Component} from "angular2/core";@Component({})export class AppComponent{ constructor(){ $.isEmptyObject({}); }} 我安装了jQuery打字,所以打字稿不
我有一个非常简单的文件:
/// <reference path="../typings/browser/ambient/jquery/jquery" />
import {Component} from "angular2/core";

@Component({})
export class AppComponent{

    constructor(){
        $.isEmptyObject({});
    }

}

我安装了jQuery打字,所以打字稿不会抱怨没有识别$.但现在问题在于抱怨问题中的问题:

Error:(1679,13) TS2403: Subsequent variable declarations must have the same type.  Variable '$' must be of type 'JQueryStatic',but here has type 'cssSelectorHelper'.

出现此问题是因为angular-protractor声明了$,但是作为cssSelectorHelper而不是JQueryStatic对象.

事情是……我根本不使用量角器!!!为什么在从angular2 / code导入东西时它会被添加?有没有一个像样的解决方法,直到Angular家伙解决这个问题,如果他们做的话.

注意:在量角器文件中注释掉定义并不是一个不错的解决方法,我正在寻找永久性的东西,当别人抓住项目并运行干净安装或更新角度库时,这些东西不会消失.

在d.ts文件中替换
declare module "jquery" {
    export = $;
}
declare var jQuery: JQueryStatic;
declare var $: JQueryStatic;

declare module "jquery" {
    export = jQuery;
}
declare var jQuery: JQueryStatic;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读