Reputation: 2071
I have problem with writing in TypeScript & ReactJS. I have no idea how to import external libraries and use them properly in the code.
I'm trying to use react-autosuggest
in my project so I'm:
react-autosuggest
with npm install --save react-autosuggest
typings install --global --save dt~react-autosuggest
Here I have problem, because I still have problems with importing it.
When I'm trying to import it with import * as autosuggest from 'react-autosuggest'
I'm getting error
error TS2497: Module ''react-autosuggest'' resolves to a non-module entity and cannot be imported using this construct.
When I'm importing with import Autosuggest from 'react-autosuggest'
another error appears:
error TS1192: Module ''react-autosuggest'' has no default export.
Could you guide me how to do it?
Upvotes: 0
Views: 931
Reputation: 921
To fix your import use require:
import AutoSuggest = require("react-autosuggest");
new AutoSuggest();
The export of the module is done with the export =
syntax. Refer to this SO for details on why you need to import this with require: https://stackoverflow.com/a/29598404/5324369
Upvotes: 2