TypeScript allows-generate definition files for your own libraries. This lesson shows what to organize your project and generate the definition files so it others projects can use your Library with TypeScript.
If you ' re writing a library and you want to generate your own definition files, just make sure and add declaration to your Tsconfig:
{ "compileroptions": { "RootDir":"src", "Module":"Commonjs", "Target":"ES5", "Noimplicitany":false, "Sourcemap":false, "OutDir":"./dist", "Noemitonerror":true, "experimentaldecorators":true, "Emitdecoratormetadata":true, "declaration": True }, "Exclude": [ "Node_modules", "Typings/main", "typings/main.d.ts" ]}
An error that would show up sometimes, it's ll say you'll have a duplicate definition of app, so your want to make Sur E in your tsconfig you ' ve excluded dist and so that you avoid have these duplicate definitions.
{ " : {...}, " " : [ " node_modules , "Dist", typings/main " , " typings/main.d.ts "}
To let other people easily import your stuff, you can create a INDEX.TX are dist:
// index.ts from './main'from'./interfaces ';
Export Everythinig They need in index.ts file.
So they can do:
Import from ' your-Lib'
For Typings, in Package.json:
" typings " " ./dist/index.d.ts "
That is, when the package gets added to typing and someone loads it up, they ' ll get the index file, and then they ' ll ha ve access to everything off the how we structured our library.
[TypeScript] Generating Definition Files