javascript – Typescript: Could not find a declaration file for module react-cards

javascript – Typescript: Could not find a declaration file for module react-cards

Youre importing an npm packages which lacks type information.

In your example, TypeScript doesnt understand the properties of Card when imported. TypeScript is not able to detect a type and refers to any, which essentially means untyped.

For many untyped packages there are @types npm packages which add those typings for you. You can find them here: microsoft.github.io/TypeSearch

Unfortunately, theres no @types/react-card package, but you have options:

  1. You could write the typing information for react-cards by yourself and save it into a react-cards.d.ts file.

  2. Disable the warning inside your tsconfig.json by setting noImplicitAny: false – Reference : https://www.typescriptlang.org/docs/handbook/compiler-options.html

Further information: typescript github thread Importing untyped JS modules

If youre using VS Code, theres a quick fix suggestion for this you can invoke with Ctrl + .

Install

You can also automatically add all missing types with typesync like this:

npx typesync

If the package doesnt have its own types, and it hasnt been added to DefinitelyTyped, youll need to add a new definitions file

Further Reading

javascript – Typescript: Could not find a declaration file for module react-cards

Leave a Reply

Your email address will not be published.