[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.

时间: 2024-08-02 15:50:09

[TypeScript] Generating Definition Files的相关文章

What you should know about .so files

In its early days, the Android OS was pretty much supporting only one CPU architecture: ARMv5.Do you know how many it does support now? … 7! Seven distinct CPU-architectures are currently supported by the Android OS: ARMv5, ARMv7 (since 2010), x86 (2

[TypeScript] Using Typings and Loading From node_modules

Using TypeScript when installing packages from npm often requires you to install related definition files. This lesson shows you how to use typings to install es6-shim then how to configure SystemJS to load from node_modules. Install: npm install --s

[TypeScript] Using Lodash in TypeScript with Typings and SystemJS

One of the most confusing parts of getting started with TypeScript is figuring out how to use all the libraries that you know and love from JavaScript. This lesson walks you through including Lodash in your project, installing Lodash definition files

TypeScript手册翻译系列12-编写.d.ts文件

Writing .d.ts files When using an external JavaScript library, or new host API, you'll need to use a declaration file (.d.ts) to describe the shape of that library. This guide covers a few high-level concepts specific to writing definition files, the

[TypeScript] Understanding Generics with RxJS

Libraries such as RxJS use generics heavily in their definition files to describe how types flow through different interfaces and function calls. We can provide our own type information when we create Observables to enable all of the auto-complete &

JavaScript Libraries In A TypeScript Application, Revisited

If you haven't already gotten involved with it, you'll probably know that TypeScript is becoming increasingly popular. Being able to use a superset of javascript in a typed language that compiles down to JavaScript is a great thing. However,if you've

How To Use XDOLoader to Manage, Download and Upload Files? (文档 ID 469585.1)

Applies to: BI Publisher (formerly XML Publisher) - Version 5.6.3 to 5.6.3 [Release 5] Information  in this document applies to any platform. Oracle XML Publisher - Version: 11.5.10 Checked for relevance on 18-MAR-2013 Goal How to use XDOLoader to Ma

How To Use XDOLoader to Manage, Download and Upload Files? (DOC ID 469585.1)

In this Document Goal Fix     Downloading Files   Uploading Files References Applies to: BI Publisher (formerly XML Publisher) - Version 5.6.3 to 5.6.3 [Release 5]Information in this document applies to any platform.Oracle XML Publisher - Version: 11

Autotools Mythbuster

Preface Diego Elio?"Flameeyes"?Pettenò Author and Publisher?<[email protected]> SRC=https://autotools.io/index.html David J.?"user99"?Cozatt Miscellaneous Editing?<[email protected]> Copyright ? 2009-2013 Diego Elio Pettenò