You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actual behavior:
The TypeScript compiler option --declaration produces definition files that mirror the source.ts structure and honor the tsconfig.json settings.
npm uses the "main" field in package.json to identify entry point to the module.
This allows substantial flexibility in how source and distribution directory structures are organized.
However, when such a module is included in a different TypeScript module, the TypeScript compiler seems to require an index.d.ts be present in the base directory of the module.
This can be as simple as a one-liner: export * from './dist/index;, but it's still a departure
from default npm behavior.
Expected behavior:
TypeScript should seek the default definition file that mirrors the "main" field of package.json
This would be a heavy breaking change at this point, a lot of Typings projects follow the structure and rely on TypeScript not picking it up without an explicit reference in package.json. For reference, maybe you're after https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html which has documentation on how to point to dist/index.d.ts (by using typings or types in package.json).
nit: the behaviour of "main" is a Node.js standard (docs here), not an npm thing. npm just conforms to Node.js standards, and the question here is really whether TypeScript should conform to this Node.js standard too.
@blakeembrey thanks for the link. I missed the "types" field in my (non!) reading of the manual and spent many hours chasing my tail. 😬
Especially given the --declaration compiler option which behaves without surprise, this strikes me as odd. I can't think of a use-case when it is advantageous to not have a type-definition file mirror the entry-point to a module. Would you have an example?
TypeScript Version: 2.0.3
Actual behavior:
The TypeScript compiler option
--declaration
produces definition files that mirror the source.ts structure and honor thetsconfig.json
settings.npm
uses the"main"
field inpackage.json
to identify entry point to the module.This allows substantial flexibility in how source and distribution directory structures are organized.
However, when such a module is included in a different TypeScript module, the TypeScript compiler seems to require an
index.d.ts
be present in the base directory of the module.This can be as simple as a one-liner:
export * from './dist/index;
, but it's still a departurefrom default
npm
behavior.Expected behavior:
TypeScript should seek the default definition file that mirrors the
"main"
field of package.jsonCode
With a directory structure that looks like this:
And the package.json like this:
For this module to be importable in other typescript modules, TypeScript expects a root
index.d.ts
to be present like this:The text was updated successfully, but these errors were encountered: