I recently wrote a blog post about this. To summarize, you can use autodts if you replace index.ts with api.ts containing the following:
export {default as Token} from './api/Token';
Make sure api.ts is in the same place as the api directory (next to, not inside it).
Then you need the package.json file:
{ "name": "api", "version": "1.0.0", "main": "dist/api.js", "scripts": { "preinstall": "npm install autodts", "postinstall": "autodts link", "prepublish": "tsc && autodts generate" }, "typescript": { "definition": "index.d.ts" }, "dependencies": { "autodts": "~0.0.4" }, "devDependencies": { "@lib/autodts-generator": "~0.0.1", "typescript": "~1.5.3" } }
It is important that the api package name matches the api.ts file and api directory. This way, both Node.js and the TypeScript compiler will look in the same places when using your package.
Finally, you need the tsconfig.json file:
{ "compilerOptions": { "declaration": true, "module": "CommonJS", "target": "es5", "outDir": "dist" }, "files": [ "api.ts" ] }
Now npm install compile your package and create the associated index.d.ts file defined in the definition setting in package.json .
To use your package, you can do something like:
/// <reference path = "api/index.d.ts" /> import {Token} from 'api'; class foo { key: Token; }
You can use the autodts link to update the reference path , check the blog post and / or automatically process documents for this.
The resulting index.d.ts contains:
/// <reference path="index.ref.d.ts" /> declare module 'api/Token' { interface Token { code: string; } export default Token; } declare module 'api' { export { default as Token } from 'api/Token'; }
index.ref.d.ts and api.js are empty.