zoukankan      html  css  js  c++  java
  • [TypeScript] Generating Definition Files

    TypeScript allows you to generate definition files for your own libraries. This lesson shows you how to organize your project and generate the definition files so that 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 will show up sometimes, it'll say you'll have a duplicate definition of app, so you want to make sure in your tsconfig you've excluded dist, so that you avoid having these duplicate definitions.

    {
        "compilerOptions": {
              ...
        },
        "exclude": [
            "node_modules",
            "dist",
            "typings/main",
            "typings/main.d.ts"
        ]
    }

    To let other people easily import your stuff, you can create a index.tx is dist:

    // index.ts
    
    export * from './main';
    export * from './interfaces';

    Export everythinig they need in index.ts file.

    So they can do:

    import  {App, Person, SocialNetwork} from 'Your-Lib'

    For typings, in package.json:

    "typings": "./dist/index.d.ts"

    that way, when that package gets added to typing and someone loads it up, they'll get this index file, and then they'll have access to everything off of how we structured our library.

  • 相关阅读:
    《实战Java高并发程序设计》读书笔记一
    《实战Java高并发程序设计》读书笔记二
    SprintBoot学习(三)
    SprintBoot学习(二)
    SprintBoot学习(一)
    jQuery学习(三)
    jQuery学习(二)
    jQuery学习(一)
    利用activeX控件在网页里自动登录WIN2003远程桌面并实时控制
    上传读取Excel文件数据
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5582616.html
Copyright © 2011-2022 走看看