Reputation: 441
I’m trying to setup a new project with React, and I’m thinking in replacing PropTypes with TypeScript.
But I want to know if I’m going to have integration issues.
For example:
react-redux
) with TypeScript + Reactreact-bootstrap
My main concern is related to importing from TypeScript a non-TypeScript code.
Any clues or experience with this?
Upvotes: 3
Views: 3644
Reputation: 3507
well you can use react redux with typescript just you need to install react-redux types:
npm install @types/react-redux
and types for react-bootstrap :
npm install @types/react-bootstrap
but still there is some problem with FormControl
and Button
events!
Upvotes: 2
Reputation: 2020
You can import Javascript libraries in your Typescript project. I do that all the time, unfortunately. Some libraries have community-typed types which you can install by running npm i @types/mypackage --dev
.
Otherwise, you will have to create an empty TS module declaration for the package:
Adhering to convention, create a file named mypackage.d.ts somewhere in your src
directory. (I usually place it in src/types/
)
mypackage.d.ts should contain declare module "mypackage";
Now, whatever you import from the mypackage will have type any.
Upvotes: 6
Reputation: 2403
There is an open source organisation called DefinitelyTyped
which is in charge of adding types to all those libraries that are not TS by default.
In your case if you are using react-redux
, you might want to install @types/react-redux
this way.
npm install @types/react-redux --dev
Check the organisation in Github:
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-redux
This is only an example they have hundreds of types packages for different libraries.
Upvotes: 1