C
C
chelnokov_a2021-07-22 10:15:06
typescript
chelnokov_a, 2021-07-22 10:15:06

How to extend the types of an installed library?

Good afternoon.

I use swiper. Delivered for it @types/swiper
However, as I understood types are described not all. Specifically, I get this error.

60f91ab6c1a3d532392519.png

I tried to override interface AutoplayOptions like this

interface AutoplayOptions {
    delay: number;
    enable: boolean;
}


But it doesn't work. Please tell me how to resolve this issue. Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Shvedov, 2021-07-22
@mmmaaak

you need a Declaration Merge, you can google it as an example:

declare module 'swiper' {
  interface AutoplayOptions {
   // тут новые свойства, которыми нужно расширить библиотечный интерфейс
  }
}

V
Vasily Bannikov, 2021-07-22
@vabka

However, as I understand, not all types are described. Specifically, I get this error.

How did you understand?
It seems to me that you are inventing some non-existent parameters, or those that existed in older versions, since there is not a word about any enable or enabled in the documentation:
https://swiperjs.com/swiper-api#autoplay-parameters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question