dts-bundle-generator: Could not find a declaration file for module
Bug report
I am importing a specific file from a library on npm, e.g. import file1 from 'someLib/src/file1'. To get its types to work (from @types/someLib), I have to basically reassign its types to that specific file by including a separate someLib.d.ts declaration file in my project that looks like this:
declare module 'someLib/src/file1' {
import someLib from 'someLib';
export default someLib;
}
Both tsc and my IDE integration are okay with this and pick up the types, but dts-bundle-generator fails to see it somehow and throws the following error:
src/consumer.ts(1,19): error TS7016: Could not find a declaration file for module 'someLib/src/file1'. 'node_modules/someLib/src/file1.js' implicitly has an 'any' type.
I can get it to pass if I set "strict": false in tsconfig.json, but I don’t want to do that. As a workaround, I can prefix the import with a comment to disable type-checking (// @ts-ignore before import someLib from 'someLib/src/file1) or create a separate tsconfig.json just for dts-bundle-generator with strict disabled, but I thought I should bring it up here to see if it’s a bug or if there’s some configuration I’ve got wrong.
This might be related to #50 but when I tried a triple-slash referenced as proposed there, it included the contents of someLib.d.ts in the generated .d.ts which threw several errors when it attempted to validate the generated file (and I’ve been told the community is moving from triple-slash references to modules anyway?). I don’t understand enough about the declare module and import interop/compatibility yet to fully grasp what’s possible and what isn’t, but I don’t think I can import my someLib.d.ts manually. Also, the usage of someLib is internal only so the types do not need to appear in the output of dts-bundle-generator.
Additional context
CLI command and options:
dts-bundle-generator --umd-module-name myLib --out-file types/myLib.d.ts src/myLib.ts
P.S. Thanks for your work, this project is great. ❤️
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 15 (9 by maintainers)
Great, no bug after all! Thanks again.
Interesting, nice find! I see also including
jssha-srcin thetypesarray intsconfig.jsonworks as an alternative to the triple-slash reference, which I think I prefer.Additionally, it seems I can nest the custom module declaration in a structure that mirrors the actual types and refer to it as such (replacing
jssha-srcwithjssha/src):👍
Thanks @timocov, I think this is a fine workaround for now. I appreciate you digging into this.