
Ask HN: TypeScript 2 module import – ignore folder levels for external libraries - fetbaffe
I have two repositories in TypeScript, one project and one library. Both of them have a <i>src</i> directory where all TypeScript files are committed.<p>I already have npm up and running in the project with the library as a dependency.<p>I can do from a .ts file in my project&#x27;s <i>src</i> directory<p><pre><code>  import { Foo } from &quot;@vendor&#x2F;my-lib&#x2F;src&#x2F;Foo&quot;;
</code></pre>
As you can see there is this annoying <i>src</i> directory in the import. Ideally a project should be unaware about the internals of a library, e.g<p><pre><code>  import { Foo } from &quot;@vendor&#x2F;my-lib&#x2F;Foo&quot;;
</code></pre>
Can this be solved?<p>Best would be if the library&#x27;s <i>tsconfig.json</i> could contain the configuration so that all consumers of the library uses it the same way.<p>But if that is not possible, the projects <i>tsconfig.json</i> will suffice.<p>Any hints? Quite hard to find any solid up-to-date documentation for this.<p>https:&#x2F;&#x2F;www.typescriptlang.org&#x2F;docs&#x2F;handbook&#x2F;module-resolution.html
======
amk_
This seems more like a stackoverflow type question, but...

Set the "main" option in the library's package.json to a bundle or index file
that exports the public interfaces to your library. Don't expose every source
file.

~~~
fetbaffe
Thanks. Seems like most TypeScript projects creates as _index.ts_ file that
just exports whatever is needed and the the compiled _index.js_ is exposed in
the "main" option. And if I understand correctly that will give you a
_index.d.ts_ that you can refer in the "typings" option in _package.json_.

