Closed deadcoder0904 closed 3 years ago
Meanwhile I'm setting allowSyntheticDefaultImports
to true
in tsconfig.json
:)
Sorry, I don't use VSCode or TypeScript, so I'm not sure what issue you are having. Somebody contributed type support a while back -- is it as simple as installing that?
npm install --save-dev @types/react-slider
I installed that already but TypeScript yelled at me. Doing this fixed the issue but maybe the types can be improved so we don't have to set that flag in tsconfig.json
.
Idk TypeScript very well either. Just started using it so don't know as well what's wrong 🤔
The current fix works for me but maybe someone else who knows TS well can chime in :)
The error
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
could be fixed by putting export default
instead of export =
in @types/react-slider
.
But I don't know if this raises compatibility issues. Any input @axelboc ?
You're right @loichuder, it should be export default
, since that's how ReactSlider
is exported in https://github.com/zillow/react-slider/blob/master/src/components/ReactSlider/ReactSlider.jsx.
Until this is fixed, it seems the best solution is actually to import the package with this TypeScript syntax: import ReactSlider = require('react-slider');
, as explained here: https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
Or use allowSyntheticDefaultImports
in tsconfig.json
which is much cleaner imo :)
Thanks all for investigating! Going to close this since the problem is external.
This should now be fixed by https://github.com/DefinitelyTyped/DefinitelyTyped/pull/50819 (published in @types/react-slider@1.1.1
)
Description
When I use
import ReactSlider from 'react-slider'
I get the following error (red-squiggly lines) in VSCode:The way to overcome
allowSyntheticDefaultImports
is to use it asimport * as ReactSlider from 'react-slider'
so I tried that & my console was filled with errors & the app crashed:The app doesn't crash when I use
import ReactSlider from 'react-slider'
but I get red-squiggly lines which I always get rid of since I use TS.Would love to find a solution to this?