Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

typescript

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.

like image 984
Timaayy Avatar asked Jul 04 '26 20:07

Timaayy


1 Answers

I believe the compiler resolves to importing from @types/package if you import directly from the package.

like image 50
Parvesh Kumar Avatar answered Jul 06 '26 12:07

Parvesh Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!