Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular with @types/swiper

I'm using @types/swiper in Angular 6 project and I'm getting an error (Cannot use 'new' with an expression whose type lacks a call or construct signature) when trying to create a new instance of Swiper.

StackBlitz

like image 307
Liad Idan Avatar asked Jul 14 '26 11:07

Liad Idan


1 Answers

The declaration of the swiper module in @types/swiper is wrong: the declaration says that the module has a named export Swiper of the Swiper class, but it actually has a default export of the class (or an export assignment depending on whether your bundler uses the CommonJS or the ES6 version: argh, stupid packaging). I've submitted a pull request to DefinitelyTyped to attempt to fix the declaration. If you use my modified declaration (see this answer for the possible ways to do that), your code should compile successfully.

like image 122
Matt McCutchen Avatar answered Jul 16 '26 13:07

Matt McCutchen