From e132ee8bf420bc7fa38054aaf40e664c2f93dc28 Mon Sep 17 00:00:00 2001 From: Vlad Date: Wed, 18 Aug 2021 16:01:14 +0300 Subject: [PATCH] feat(angular): better typing --- src/angular/src/swiper.component.ts | 9 +++++++-- src/types/modules/controller.d.ts | 2 +- src/types/modules/virtual.d.ts | 1 + src/types/swiper-class.d.ts | 18 +++++++++++++++++- tsconfig.json | 6 ++++-- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/angular/src/swiper.component.ts b/src/angular/src/swiper.component.ts index 9ffbf6333..09299be53 100644 --- a/src/angular/src/swiper.component.ts +++ b/src/angular/src/swiper.component.ts @@ -560,7 +560,9 @@ export class SwiperComponent implements OnInit { if (swiperParams.loop) { swiperRef.loopedSlides = this.loopedSlides; } - if (swiperRef.virtual && swiperRef.params.virtual.enabled) { + const isVirtualEnabled = + typeof swiperRef.params.virtual !== 'boolean' && swiperRef.params.virtual.enabled; + if (swiperRef.virtual && isVirtualEnabled) { swiperRef.virtual.slides = this.slides; const extendWith = { cache: false, @@ -573,7 +575,10 @@ export class SwiperComponent implements OnInit { if (isPlatformBrowser(this._platformId)) { this.swiperRef = swiperRef.init(this.elementRef.nativeElement); - if (this.swiperRef.virtual && this.swiperRef.params.virtual.enabled) { + const isEnabled = + typeof this.swiperRef.params.virtual !== 'boolean' && + this.swiperRef.params.virtual.enabled; + if (this.swiperRef.virtual && isEnabled) { this.swiperRef.virtual.update(true); } this._changeDetectorRef.detectChanges(); diff --git a/src/types/modules/controller.d.ts b/src/types/modules/controller.d.ts index 95faaafef..74b99c80b 100644 --- a/src/types/modules/controller.d.ts +++ b/src/types/modules/controller.d.ts @@ -5,7 +5,7 @@ export interface ControllerMethods { * Pass here another Swiper instance or array with Swiper instances that should be controlled * by this Swiper */ - control?: Swiper; + control?: Swiper | Swiper[]; } export interface ControllerEvents {} diff --git a/src/types/modules/virtual.d.ts b/src/types/modules/virtual.d.ts index 01fb16822..48b270868 100644 --- a/src/types/modules/virtual.d.ts +++ b/src/types/modules/virtual.d.ts @@ -71,6 +71,7 @@ export interface VirtualData { } export interface VirtualOptions { + enabled?: boolean; /** * Array with slides * diff --git a/src/types/swiper-class.d.ts b/src/types/swiper-class.d.ts index 495de64ba..ba6969bce 100644 --- a/src/types/swiper-class.d.ts +++ b/src/types/swiper-class.d.ts @@ -46,6 +46,11 @@ interface Swiper extends SwiperClass { */ params: SwiperOptions; + /** + * Object with original initialization parameters + */ + originalParams: SwiperOptions; + /** * Dom7 element with slider container HTML element. To get vanilla HTMLElement use `swiper.el` */ @@ -71,6 +76,13 @@ interface Swiper extends SwiperClass { */ slides: Dom7Array; + /** + * If you use `slidesPerView:'auto'` with loop mode you should tell to Swiper how many slides it should loop (duplicate) using this parameter + * + * @default null + */ + loopedSlides: number | null; + /** * Width of container */ @@ -304,10 +316,14 @@ interface Swiper extends SwiperClass { */ attachEvents(): void; + loopCreate(): void; + + loopDestroy(): void; + /** * Initialize slider */ - init(): void; + init(el?: HTMLElement): Swiper; /** * Destroy slider instance and detach all events listeners diff --git a/tsconfig.json b/tsconfig.json index 50df6fac9..f59dc28a1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,8 @@ "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, + "strict": false, + "strictPropertyInitialization": false, "declaration": false, "downlevelIteration": true, "experimentalDecorators": true, @@ -13,8 +15,8 @@ "module": "es2020", "lib": ["es2018", "dom"], "paths": { - "swiper": ["src", "build/swiper.esm.js"], - "swiper/*": ["src/*"] + "swiper": ["build", "build/swiper.esm.js"], + "swiper/*": ["build/*"] } } }