I had this same problem but not necessarily relating to typescript, so I struggled a bit with these different options. I am making a very basic create-react-app using a specific module react-portal-tooltip,
getting similar error:
Could not find a declaration file for module 'react-portal-tooltip'. '/node_modules/react-portal-tooltip/lib/index.js' implicitly has an 'any' type. Try
npm install @types/react-portal-tooltip
if it exists or add a new declaration (.d.ts) file containingdeclare module 'react-portal-tooltip';
ts(7016)
I tried many steps first - adding various .d.ts
files, various npm installs.
But what eventually worked for me was touch src/declare_modules.d.ts
then in src/declare_modules.d.ts
:
declare module "react-portal-tooltip";
and in src/App.js
:
import ToolTip from 'react-portal-tooltip';
// import './declare_modules.d.ts'
I struggled a bit with the different locations to use this general 'declare module' strategy (I am very much a beginner) so I think this will work with different options but I am included paths for what worked work me.
I initially thought import './declare_modules.d.ts'
was necessary. Although now it seems like it isn't! But I am including the step in case it helps someone.
This is my first stackoverflow answer so I apologize for the scattered process here and hope it was still helpful! :)