OfficialCRUGG
OfficialCRUGG

Reputation: 61

Problems with Dependencies after switching to TypeScript

I have just switched one of my React Projects over to TypeScript, which is actually my first time using it. So I renamed my App.jsx file to App.tsx and got some errors with my dependencies. Most of them I could fix by using npm i @types/{package}. There are three errors left though:

1) For two of my packages, there is no @types package, as they aren't that popular. It says "Could not find a declaration file for module [...] [...]/index.js' implicitly has an 'any' type. [...]" In the rest of the error it says that I should try to install the @types package if it exists, which doesn't. If it doesn't exist, it says something about some declaration file, but I wasn't able to find any information about that online.

2) It almost says the exact same thing for the 'react' package, even though I installed the @types package of it. Instead of telling me to install the package it says: "If the 'react' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react'" which I don't understand what it is supossed to mean.

Also, I copied the tsconfig.json from the create-react-app typescript template (create-react-app {name} --typescript

Upvotes: 0

Views: 1129

Answers (1)

Ovidiu G
Ovidiu G

Reputation: 1273

1) You can make a types folder where you will keep all the declarations that you can't find under @types. Basically you make a some-react-component.d.ts file where you declare:

declare module "some-react-component";

2) You can try to import react this way: import * as React from "react"; and see if that's fixing it.

Upvotes: 1

Related Questions