I am wanting to add types to a component library written purely in Javascript that I am not currently able to add directly to. I have followed this example for adding declarations to third party packages, which almost got me there. The current issue I am having is the package structure.
The package is located in node_modules
as @company/company-widgets
, I am not exactly certain how to handle the inner module as tsc
is unable to find and associate the declaration files I have added. The compiler's recommendation is
Try `npm install @types/company__company-widgets` if it exists or add a new declaration (.d.ts) file containing `declare module 'company__company-widgets';`
I have tried the following:
- Modifying
tsconfig.json
with"typeRoots": ["@types", "./src/@types"] and adding an
index.d.ts` file with the module declaration specified in the compiler message - With the above
tsconfig.json
changes, adding directories undersrc/@types
to match that ofnode_modules
- I also changed the declaration to have a
module
named company and anamespace
of __company-widgets - I also got desparate and started messing around with
node_modules
by placing a declaration in there
None of these have got the declaration found unfortunately, so I have been thinking it is unable to associate the module name in the declaration to the package name. Any suggestions or answers would be greatly appreciated. Thanks!