Property 'select2' does not exist on type 'JQuery<HTMLElement>'

Viewed 3049

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.

2 Answers

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.

Related