Reputation: 98
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:
tsconfig.json
with "typeRoots": ["@types", "./src/@types"] and adding an
index.d.ts` file with the module declaration specified in the compiler messagetsconfig.json
changes, adding directories under src/@types
to match that of node_modules
module
named company and a namespace
of __company-widgetsnode_modules
by placing a declaration in thereNone 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!
Upvotes: 0
Views: 886
Reputation: 30949
The compiler's recommendation is wrong: the module declaration should be declare module '@company/company-widgets';
, not declare module 'company__company-widgets';
. I fixed this recently and the fix should be in TypeScript 3.1.
Upvotes: 1