Typings conflict (angular-protractor vs jquery) #1126

Closed
AloeDream opened this Issue Jul 16, 2016 · 10 comments

Projects

None yet

6 participants

@AloeDream
AloeDream commented Jul 16, 2016 edited

Steps to reproduce.
In my case I use signalR library and typings for it, added to typings.json at project root. Signalr uses jquery.
So when trying to use something like in one of my services:
this.hubConnection = jQuery.hubConnection();
or this:
this.hubConnection = $.hubConnection();

I'm getting error both in editor and during build:

Subsequent variable declarations must have the same type.
Variable '$' must be of type 'cssSelectorHelper', but here has type 'JQueryStatic'.

I've tried to reference only signalR .d.ts file in my code, tried using signalR's alternative alias for "$", but during build it fails anyway as it concats everything I guess.

Expected/desired behavior
I think test (where angular-protractor belongs, as I understand) should be somehow separated in build process to avoid such conflicts.

related issue https://github.com/DefinitelyTyped/DefinitelyTyped/issues/2734

@mgechev
Owner
mgechev commented Jul 16, 2016

You can exclude the protractor's type definition if you pass: "!PATH_TO_PROTRACTOR_DEF.d.ts". Since most likely the protractor's type definition is referenced within typings/index.d.ts you'll have to exclude this file as well.

@mgechev mgechev closed this Jul 16, 2016
@vinaychandra

@mgechev, I could run with jquery in normal npm start. The issue when running with gulp test is that the error is $ is not defined rather than pointing to some other thing.

@ludohenin
Collaborator

Have you include a ref to jQuery in karma.conf file ?

@vinaychandra
vinaychandra commented Aug 21, 2016 edited

Yes. Also, there are no 404 errors on console. And $ works on console of karma browser as expected. It just does not work on unit tests 

@Sn3b
Sn3b commented Aug 22, 2016

Have you tried to change the type of $ from JQueryStatic to cssSelectorHelper in jquery.d.ts from the typings folder?

@vinaychandra
vinaychandra commented Aug 22, 2016 edited

I never have mentioned the type for $. I used any for $. It works fine for normal server but fails for karma 

@Sn3b
Sn3b commented Aug 22, 2016

I'm talking about the typing file you downloaded from definitely typed, it mentions that $ is of type JQueryStatic. Try to change the type to cssSelectorHelper.

The only problem is that whenever you run npm install it'll re-download the typings file for jquery and will reset this...

@vinaychandra

@Sn3b, I did not use the d.ts file for jQuery. I circumvented the file requirement by using the alternative declare var $: any. This would make typescript accept $ as any variable and thus eliminating the variable.

@ashblue
ashblue commented Nov 23, 2016

Overriding the $ variable to circumvent typings really doesn't solve the issue at hand. See #1645 for my findings on the issue with a potential / possible solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment