Reputation: 51
I am using Angular 4 with select2
plugin. I have already added @types
for jquery
and select2
. Vscode intellisense shows as a method select2 and doesnt throw any error, but angular-cli's compilation fails.
Upvotes: 4
Views: 4100
Reputation: 22797
In my case, that's because I imported another library (sweetalert2), with the wrong jQuery definition.
In sweetalert2.d.ts
line 885:
/**
* These interfaces aren't provided by SweetAlert2, but its definitions use them.
* They will be merged with 'true' definitions.
*/
// tslint:disable:no-empty-interface
interface JQuery {
}
This override JQuery
definition with the wrong result (which originally should be JQuery<T = HTMLElement>
). After removing it everything runs correctly.
Upvotes: 0
Reputation: 2267
I had a similar issue and fixed it by importing:
import 'select2';
which I had installed earlier:
npm install select2 --save
Once you do that, you can use the library through jQuery as usual, and your IDE won't complain about it.
Upvotes: 2