One of my challenges involves creating type declarations for outdated dependencies that produce CJS modules and lack typings. An example is the aabb-3d module (although this issue isn't specific to that particular module).
To generate the declaration, I typically use a command like this:
tsc node_modules/aabb-3d/index.js
--allowJs
--declaration
--emitDeclarationOnly
--outFile types/aabb-3d/index.d.ts
The generated declaration file looks something like this:
declare module "index" {
export = AABB;
function AABB(pos: any, vec: any): AABB;
//...
However, my code editor doesn't recognize these typings because it expects the declaration to reference the module as aabb-3d
, not index
.
If I manually update the generated d.ts
file to reflect the correct module name, my editor functions properly and provides accurate code hints for the older module. How can I ensure that tsc
generates correct declaration files automatically?