I am working on lets say package A that is intended to be used in another package B (sort of as a plugin) but my package A depends on the types defined in package B. I am using Typescript 4.3.4
My initial thought was to import just the types from package B into package A but that presented me with the following problem:
I installed types to node_modules/@types/packageA inside packageB and when I tried to import with import { someType } from '@types/packageA' and build I got the following error: TS6137: Cannot import type declaration files.
Now if I instead installed types to node_modules/packageA-types inside packageB and import with import { someType } from 'packageA-types' it works and I do not get the error when I build.
Why does the first method fail and why does the second method work?
I read a few other stackoverflow posts that talked about normal/local vs global/ambient Typescript modules but I didn't quite understand how that played into this situation.
I believe the compiler resolves to importing from @types/package if you import directly from the package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With