react-slick icon indicating copy to clipboard operation
react-slick copied to clipboard

TypeScript can't find Slider

Open sidonaldson opened this issue 5 years ago • 8 comments

TYPESCRIPT - yay.

I'm currently required to use TS in my project but I can't seem to find any documentation about it.

in node_modules/@types/react-slick there is a definition file which seems to extend React.Component and export Slider

export default Slider;

but Slider isn't available as a namespace or an interface.

Can anyone offer any insight into getting this working? Thanks!

sidonaldson avatar Jul 29 '19 08:07 sidonaldson

Did you install @types/react-slick ? (Additional NPM package)

oxodesign avatar Aug 15 '19 11:08 oxodesign

@oxodesign yup

The only way I could get this to work is to import the typings into my own typings file, which in turn then need to be imported because TS treats it as a module.

i.e.

import { Settings as CarouselSettings } from 'react-slick';

interface CarouselProps {
    carouselSettings?: CarouselSettings;
    children?: React.ReactChild[];
}

sidonaldson avatar Aug 15 '19 11:08 sidonaldson

Another variation to get this to work, after installing @types/react-slick in devDependencies:

in your .d.ts file:

import Slider, { Settings } from 'react-slick';
declare module 'react-slick' {
  export { Slider, Settings };
}

then import normally in your component.

import Slider, {Settings} from 'react-slick';

VS Code Go To Definition will now go correctly to the node_modules index.d.ts.

john20xdoe avatar Jan 07 '21 06:01 john20xdoe

@john20xdoe that is the answer I was looking for! Thanks

sidonaldson avatar Jan 07 '21 09:01 sidonaldson

Do we have any update on this issue?

nattri avatar May 26 '22 09:05 nattri

Very annoying. In a TS Project its impossible to use with import Slider from "react-slick";

Stophface avatar Mar 13 '23 09:03 Stophface

@john20xdoe What .d.ts file?

alxvallejo avatar Apr 03 '23 20:04 alxvallejo

Does anybody manage to make this work in typescript recently ?

razvan-ct avatar Aug 26 '23 10:08 razvan-ct