How to import cdbreact components to typescript projects

amin_gholami

Amin Gholamisani

Posted on June 29, 2022

How to import cdbreact components to typescript projects

CDBReact is one of the popular packages that updated recently and you can use it to have many reusable components for react such as Navbar, Sidebar, etc.
But if you want to have Typescript components, you will see an type error when you want to import the components:

Could not find a declaration file for module 'cdbreact'. 'C:/node_modules/cdbreact/dist/index.js' implicitly has an 'any' type.
Try npm i --save-dev @types/cdbreact if it exists or add a new declaration (.d.ts) file containing declare module 'cdbreact';

This error is because cdbreact don't have type declaration yet and you need to import this in another way like this:

const cdbreact = require('cdbreact');  
const { CDBBtN, CDBBox } = cdbreact;
Enter fullscreen mode Exit fullscreen mode

Now you can see it works without any error.
Enjoy!

💖 💪 🙅 🚩
amin_gholami
Amin Gholamisani

Posted on June 29, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related