typescript 后续变量声明必须具有相同的类型。变量 '$' 的类型必须是 'JQueryStatic',但这里的类型是 'cssSelectorHelper'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34641185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Subsequent variable declarations must have the same type. Variable '$' must be of type 'JQueryStatic', but here has type 'cssSelectorHelper'
提问by Langley
I have a very simple file:
我有一个非常简单的文件:
/// <reference path="../typings/browser/ambient/jquery/jquery" />
import {Component} from "angular2/core";
@Component({})
export class AppComponent{
constructor(){
$.isEmptyObject({});
}
}
I installed jQuery typings so typescript wouldn't complain about not recognizing $. But now the thing is complaining about the issue in the question:
我安装了 jQuery 类型,因此打字稿不会抱怨无法识别 $。但现在事情是抱怨问题中的问题:
Error:(1679, 13) TS2403: Subsequent variable declarations must have the same type. Variable '$' must be of type 'JQueryStatic', but here has type 'cssSelectorHelper'.
This issue happens because angular-protractor is declaring $ as well but as a cssSelectorHelper
instead of a JQueryStatic
object.
发生此问题是因为 angular-protractor 也在声明 $ ,但声明为 acssSelectorHelper
而不是JQueryStatic
对象。
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.
事情是......我根本没有使用量角器!!!,为什么当我从 angular2/code 导入一些东西时它会被添加?在 Angular 的人解决这个问题之前,是否有合适的解决方法,如果他们曾经这样做的话。
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.
注意:注释掉量角器文件中的定义不是一个体面的解决方法,我正在寻找一些永久的东西,当其他人获取项目并运行干净安装或当我们更新角度库时,它不会消失。
回答by Rodrigo
in the d.ts
file replace
在d.ts
文件中替换
declare module "jquery" {
export = $;
}
declare var jQuery: JQueryStatic;
declare var $: JQueryStatic;
with
和
declare module "jquery" {
export = jQuery;
}
declare var jQuery: JQueryStatic;
回答by AngularBoy
As a work around, comment out JQueryStatic and replace with cssSelectorHelper at the bottom of angular-protractor.d.ts
作为解决方法,注释掉 JQueryStatic 并替换为 angular-protractor.d.ts 底部的 cssSelectorHelper
declare var browser: protractor.IBrowser;
declare var by: protractor.IProtractorLocatorStrategy;
declare var By: protractor.IProtractorLocatorStrategy;
declare var element: protractor.Element;
// declare var $: JQueryStatic;
declare var $: cssSelectorHelper;
declare var $$: cssArraySelectorHelper;