I'm confused when creating declaration files (d.ts).
For example, I created a NPM package "a" (one CommonJS module index.ts):
export interface IPoint {
x: number;
y: number;
}
export default function sub(one: IPoint, two: IPoint): IPoint {
return {
x: one.x - two.x,
y: one.y - two.y
};
}
Compile it and generate a.d.ts:
export interface IPoint {
x: number;
y: number;
}
export default function sub(one: IPoint, two: IPoint): IPoint;
As I understand the compiler can not generate valid d.ts for CommonJS. Must use utilities as dts-generator or to wrap manually:
declare module "a"
{
export interface IPoint {
x: number;
y: number;
}
export default function sub(one: IPoint, two: IPoint): IPoint;
}
Ok. Now I am doing the package "b" (which depends on "a"):
/// <reference path="node_modules/a/a.d.ts" />
import sub from "a"
import { IPoint } from "a"
export { IPoint }
export default function distance(one: IPoint, two: IPoint): number {
var s = sub(one, two);
return Math.sqrt(s.x * s.x + s.y * s.y);
}
Ok, it work. Now a want a package "c" that depends on "b" (and so on).
How to specify the dependence in the module "b" (link to "a.d.ts")? Trying to specify in "node_modules"? Or copy "a.d.ts" to "/typings/" directory in the "b" package? And then copy "a.d.ts" and "b.d.ts" to "/typings/" in the "c" package (and so on)?
What is the point from sections "typings" in "package.json"? I write in "b/package.json":
"typings": "./b.d.ts"
And get the error when compiling "c":
Exported external package typings file 'node_modules/b/b.d.ts' is not a module.
- How to create d.ts files for CommonJS module? So that do not write manually "declare module", "reference" and etc.