Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use third-party libraries with React and TypeScript?

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:

  • Using Redux (or react-redux) with TypeScript + React
  • Issues integrating components that are not created with TypeScript
  • Problems with libraries like react-bootstrap

My main concern is related to importing from TypeScript a non-TypeScript code.

Any clues or experience with this?

like image 487
Ricardo Daniel Avatar asked Mar 15 '26 14:03

Ricardo Daniel


1 Answers

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.

like image 78
Ante Gulin Avatar answered Mar 17 '26 03:03

Ante Gulin