How to import cdbreact components to typescript projects
Amin Gholamisani
Posted on June 29, 2022
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.
Trynpm i --save-dev @types/cdbreact
if it exists or add a new declaration (.d.ts) file containingdeclare 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;
Now you can see it works without any error.
Enjoy!
Posted on June 29, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.