In my JS code I import a module like so:
const toolbox = require('../toolbox')
/**
* @param {toolbox.Hammer} hammer
*/
function useHammer(hammer) {
let nail = new toolbox.Nail()
hammer.ham(nail)
}
Now, because my tools/index.d.ts file exports toolbox as a namespace. My IDE can see that hammer has a method ham on it. Awesome! But it cannot see that toolbox has a member Nail in it.
I tried placing @module and @export tags in toolbox/index.js to no avail. I also tried placing a @type {toolbox} over top of the require statement but I'm told that toolbox is referenced directly or indirectly in its own type annotation.
How can I let my IDE know that toolbox = require('toolbox') makes toolbox correspond to my namespace?
An example toolbox/index.js and toolbox/index.d.ts for reference:
exports.Hammer = class {
ham (nail) {
if (Math.random() > 0.1) {
exports.nailCount -= 1
return 'bang!'
} else return 'Ouch my thumb!'
}
}
exports.nailCount = 100
exports.Nail = class {}
export = toolbox
export as namespace toolbox
declare namespace toolbox {
class Nail {}
class Hammer {
ham(n: Nail) : string
}
}
and my tsconfig for good measure (since it's a little cargo-culty)
{
"compilerOptions": {
"allowJs": true,
"target": "es5",
"checkJs": true,
"baseUrl": "../",
"moduleResolution": "node",
"noEmit": true
}
}


.d.tsfiles that would be excellent. But it's not a show-stopper. Some JSDoc annotations are acceptable at this stage but not preferred.