In a typescript (Angular 9) project I'm trying to import a private JS lib.
When I import it with import { myMethod } from 'my-private-repo/dist/util';
I get 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';`
I tried to fix the problem adding a declaration file in a typings
folder with the following content : declare module "my-private-repo/dist/util";
, or even with declare module "*";
but the error doesn't change, like my declaration file is not read at all while I changed my ts config to include it :
{
...
"compilerOptions": {
...
"noImplicitAny": true,
...
"typeRoots": [
"./typings",
"./node_modules/@types"
]
}
}
I don't understand why my declaration file is not recognized.
Do you have any idea ?
Thank you :)
You need to add a declaration file in one of these paths:
'my-private-repo/dist/util.d.ts'
'my-private-repo/dist/package.json'
(and specify a "types" property)'my-private-repo/dist/@types/util.d.ts'
read about how typescript load module: https://www.typescriptlang.org/docs/handbook/module-resolution.html