后续变量声明必须具有相同的类型

后续变量声明必须具有相同的类型

本文介绍了后续变量声明必须具有相同的类型.变量"$"必须为"JQueryStatic"类型,但此处为"cssSelectorHelper"类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的文件:

I have a very simple file:

/// <reference path="../typings/browser/ambient/jquery/jquery" />
import {Component} from "angular2/core";

@Component({})
export class AppComponent{

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

}

我安装了jQuery类型,因此打字稿不会抱怨无法识别$.但是现在事情在抱怨这个问题了:

I installed jQuery typings so typescript wouldn't complain about not recognizing $. But now the thing is complaining about the issue in the question:

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

之所以会发生此问题,是因为角度量角器也声明了$,但是声明的是cssSelectorHelper而不是JQueryStatic对象.

This issue happens because angular-protractor is declaring $ as well but as a cssSelectorHelper instead of a JQueryStatic object.

问题是...我根本没有使用量角器!!!,当我从angular2/code导入某些东西时为什么要添加它呢?在有经验的人解决之前,是否有一个不错的解决方法.

Thing is... I am not using protractor at all !!!, why is it getting added when I import something from angular2/code? Is there a decent workaround for this until Angular guys fix this, if they ever do.

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

Note: commenting out the definition in the protractor file is not a decent workaround, I'm looking for something permanent that won't go away when someone else grabs the project and runs a clean install or when we update the angular library.

推荐答案

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

使用

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

这篇关于后续变量声明必须具有相同的类型.变量"$"必须为"JQueryStatic"类型,但此处为"cssSelectorHelper"类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 04:46