8

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:

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.

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.

MartyIX
  • 27,828
  • 29
  • 136
  • 207
Langley
  • 5,326
  • 2
  • 26
  • 42
  • Your question is actually a duplicate of http://stackoverflow.com/questions/34546446/flattening-typescript-typings-or-interfaces/ Hopefully Angular team will fix this problem soon. – MartyIX Jan 07 '16 at 07:02
  • They are related, not duplicated. That one seems more generic and is asking for the whole Angular 2 as a DefinitelyTyped lib. I just want to solve it for this specific jquery conflict, because it's stupid they are calling protractor in the core module in the first place. – Langley Jan 07 '16 at 18:44
  • So your issue is this https://github.com/angular/angular/issues/4725, right? – MartyIX Jan 08 '16 at 08:15
  • Correct, I believe this is the general one they left open for the same issue: https://github.com/angular/angular/issues/5459 and for what I saw in the master repo they might already fixed it, but they haven't released another build to npm. I'm looking for a apply only once workaround until they release the a new build in npm if they indeed fixed it. – Langley Jan 08 '16 at 15:13
  • I don't see any fix from them here: https://github.com/angular/angular/commits/master. And I believe it will be fixed globally as they promise here: https://github.com/angular/angular/issues/5807#issuecomment-169041808. But I don't know for sure, it's only my interpretation. :) – MartyIX Jan 08 '16 at 15:32
  • I thought they fixed it because I don't see the reference to protractor in core.ts, but it was core.d.ts the one that had it. So no idea if they have or they haven't but it doesn't really matter, I'm looking for a solution that works until they do. – Langley Jan 08 '16 at 15:46

2 Answers2

8

in the d.ts file replace

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

with

declare module "jquery" {
    export = jQuery;
}
declare var jQuery: JQueryStatic;
Rodrigo
  • 3,129
  • 3
  • 33
  • 61
0

As a work around, comment out JQueryStatic and replace with cssSelectorHelper at the bottom of angular-protractor.d.ts

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;
AngularBoy
  • 1,715
  • 2
  • 25
  • 35
  • You got it backwards, you have to replace cssSelectorHelper for JQueryStatic instead or simply comment the line which is what Im doing atm. It works, but every person that downloads the repo is going to have to do the same. I'm looking for an automated solution, like excluding the protractor module with node, or downloading the whole package from another source, because it seems the issue has been solved in the master repo, there's just no new build for npm yet. One more temporal workaround is the following: $.isEmptyObject({}); – Langley Jan 07 '16 at 18:46