To create the TS library that will be used by the TS project, you do not need to do much.
(Sorry if the example is too detailed.)
Library
Assuming the source files are written in TypeScript, you need the following settings:
tsconfig.json
{ "compilerOptions": { "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es5", "module": "commonjs", "removeComments": false, "sourceMap": true, "outDir": "dist/", "declaration": true }, "filesGlob": [ "**/*.ts", "!node_modules/**/*" ], "exclude": [ "node_modules", "typings/global", "typings/global.d.ts" ], "compileOnSave": true }
The important thing here is basically declarations: true , which tells the TS compiler to generate d.ts files.
package.json
{ "name": "my-typescript-library", "description": "...", "version": "1.0.0", "main": "./dist/my.service.js", "typings": "./dist/my.service.d.ts", "license": "ISC", "dependencies": { ... }, "devDependencies": { "typescript": "^1.8.10", "typings":"^1.0.4", ... } }
The important things here are the "core" and the "typing", which are the entry point for the service in the library. Therefore, if someone was require("my-typescript-library") , then the file specified here will be used. The type field is similar, but TypeScript obviously helps.
Then you transfer this library to Github, or Bitbucket, or elsewhere.
Consumer
You do not need much here.
package.json
Add a dependency on your library:
{ ..., "dependencies": { "my-typescript-library": "git+ssh://bitbucket.org/you/my-typescript-library", ... } }
In this example, you will need the SSH key.
Then you just import the lib.
my_file.ts
import {MyService} from "my-typescript-library";
So, you have this, TypeScript lib is used in a TypeScript application. Hope the answer is enough (and clear enough), otherwise just write me a line.