I'm currently facing an issue in my typescript (Angular 9) project where I am trying to import a private JavaScript library.
Upon importing it using
import { myMethod } from 'my-private-repo/dist/util';
, I encounter the following error :
Could not find a declaration file for module 'my-private-repo/dist@types/util'. 'my-private-repo/dist/util.js' implicitly has an 'any' type. Try `npm install @types/my-private-repo` if it exists or add a new declaration (.d.ts) file containing `declare module 'my-private-repo/dist/util';`
To address this issue, I attempted to create a declaration file in a folder named typings
with the content:
declare module "my-private-repo/dist/util";
, or even with declare module "*";
. However, the error persists as if my declaration file is not being recognized at all, despite modifying my tsconfig to include it:
{
...
"compilerOptions": {
...
"noImplicitAny": true,
...
"typeRoots": [
"./typings",
"./node_modules/@types"
]
}
}
I'm puzzled as to why my declaration file is not being acknowledged. Any insights on how to resolve this would be greatly appreciated!
Thank you :)