TS6137: Cannot import type declaration files when importing from @types

Viewed 463

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:

  1. 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.

  2. 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.

0 Answers
Related