question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Breakpoints not working due typescript Interface

See original GitHub issue

Hi, I’ am trying to use this lib in a typescript application. When i try to define the breakpoints, it fails to transpile from typescript with the following error:

TypeScript error in /home/yang/pfc_frontend/src/components/YACarousel/index.tsx(23,11):
No overload matches this call.
  Overload 1 of 2, '(props: Readonly<CarouselProps>): default', gave the following error.
    Type '{ 640: { plugins: { resolve: CarouselPluginFunc; options: { numberOfSlides: number; }; }[]; }; 900: { plugins: { resolve: CarouselPluginFunc; options: { numberOfSlides: number; }; }[]; }; }' is not assignable to type 'Pick<CarouselProps, "className" | "offset" | "onChange" | "draggable" | "value" | "plugins" | "itemWidth" | "slides" | "animationSpeed">'.
      Object literal may only specify known properties, and '640' does not exist in type 'Pick<CarouselProps, "className" | "offset" | "onChange" | "draggable" | "value" | "plugins" | "itemWidth" | "slides" | "animationSpeed">'.
  Overload 2 of 2, '(props: CarouselProps, context?: any): default', gave the following error.
    Type '{ 640: { plugins: { resolve: CarouselPluginFunc; options: { numberOfSlides: number; }; }[]; }; 900: { plugins: { resolve: CarouselPluginFunc; options: { numberOfSlides: number; }; }[]; }; }' is not assignable to type 'Pick<CarouselProps, "className" | "offset" | "onChange" | "draggable" | "value" | "plugins" | "itemWidth" | "slides" | "animationSpeed">'.
      Object literal may only specify known properties, and '640' does not exist in type 'Pick<CarouselProps, "className" | "offset" | "onChange" | "draggable" | "value" | "plugins" | "itemWidth" | "slides" | "animationSpeed">'.  TS2769

    21 |         itemWidth={400}
    22 |         breakpoints={{
  > 23 |           640: {
       |           ^
    24 |             plugins: [
    25 |               {
    26 |                 resolve: slidesToShowPlugin,

My code is:

import React from 'react';
import Carousel, { slidesToShowPlugin } from '@brainhubeu/react-carousel';
import '@brainhubeu/react-carousel/lib/style.css';
import ClientImage from '../../assets/cardClient.svg';
import { Container } from './styles';
import ClientItem from '../ClientItem';

const YACarousel: React.FC = () => {
  return (
    <Container>
      <Carousel
        plugins={[
          'arrows',
          {
            resolve: slidesToShowPlugin,
            options: {
              numberOfSlides: 2,
            },
          },
        ]}
        itemWidth={400}
        breakpoints={{
          640: {
            plugins: [
              {
                resolve: slidesToShowPlugin,
                options: {
                  numberOfSlides: 1,
                },
              },
            ],
          },
          900: {
            plugins: [
              {
                resolve: slidesToShowPlugin,
                options: {
                  numberOfSlides: 2,
                },
              },
            ],
          },
        }}
      >
        <ClientItem
          imgSrc={ClientImage}
          publisher={`Lucas Salles - Camisa do Santos F.C autografada`}
          message={`"Estou muito feliz pela minha compra, vou poder guardar essa lembrança do Santos!"`}
        />
        <ClientItem
          imgSrc={ClientImage}
          publisher={`Lucas Salles - Camisa do Santos F.C autografada`}
          message={`"Estou muito feliz pela minha compra, vou poder guardar essa lembrança do Santos!"`}
        />
        <ClientItem
          imgSrc={ClientImage}
          publisher={`Lucas Salles - Camisa do Santos F.C autografada`}
          message={`"Estou muito feliz pela minha compra, vou poder guardar essa lembrança do Santos!"`}
        />
      </Carousel>
    </Container>
  );
};
export default YACarousel;

The Client component is just a div with a Card like layout. Without the breakpoint, it works.

Another thing i found, is the interface:

export interface CarouselProps {
    itemWidth?: number;
    value?: number;
    onChange?(value: number): void;
    slides?: JSX.Element[];
    offset?: number;
    draggable?: boolean;
    animationSpeed?: number;
    className?: string;
    breakpoints?: Pick<CarouselProps, Exclude<keyof CarouselProps, "breakpoints">>;
    plugins?: Array<string|CarouselPluginTypes>;
}

It’s like there is something missing, to use the set breakpoint numbers properly, but i’m not sure…

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

3reactions
qchuchucommented, Sep 19, 2021

I just created a PR on DefinitelyTyped : https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55862 - I’m kinda of new to this but I think I did it the right way. Maybe if you can upvote it, that would help to give more visibility 😉

Sorry for the delay, as I had a short notice to finish my project last time, I decided to use another library. But I think we need to make this change as it keeps annoying people 😉

3reactions
qchuchucommented, Dec 17, 2020

Yep I had the same problem on my project. It’s because the breakpoint type is not good. If you change your node modules types to :

interface CarouselBreakpoint {
    [breakpointNumber: number]: Pick<CarouselProps, Exclude<keyof CarouselProps, "breakpoints">>
}

export interface CarouselProps {
    itemWidth?: number;
    value?: number;
    onChange?(value: number): void;
    slides?: JSX.Element[];
    offset?: number;
    draggable?: boolean;
    animationSpeed?: number;
    className?: string;
    breakpoints?: CarouselBreakpoint;
    plugins?: Array<string|CarouselPluginTypes>;
}

It will work properly 😃

I will propose a PR soon to fix it !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Breakpoint not hit in TypeScript file using Visual Studio 2019 ...
Set a break point in your TypeScript file line in Visual Studio · Run the application · Open the Inspector (F12 or RMB...
Read more >
typescript breakpoints can't be hit when attach running chrome ...
I made a simple typescript application. with serveral typescript files and and generated one js bundle file by “outFile”: “…/customization.js” in tsconfig. I ......
Read more >
Breakpoint not work for sourcemapped typescript when source ...
Breakpoint not work for sourcemapped typescript when source file and output file are not in a same directory ... (Depends on 1 open...
Read more >
Navigate through code by using the Visual Studio debugger
Run to a function breakpoint · While debugging, open the Call Stack window by selecting Debug > Windows > Call Stack. · In...
Read more >
Visual Studio 2017 Breakpoint not being hit with Angular, TS ...
How to fix "the breakpoint will not currently being hit. ... 2017 - Breakpoint not working with .NET Core 2, Angular, TypeScript and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found