[TypeScript] Generating Definition Files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.