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.

[TypeScript] Generating Definition Files的更多相关文章

  1. tensorboard No graph definition files were found No scalar data was found 解决方法

    logdir后面的路径不要加引号!!!! tensorboard --logdir='D:\WorkSpace\eclipse\tf_tr\train\my_graph\' 删除引号,改为: tens ...

  2. [TypeScript] Using Typings and Loading From node_modules

    Using TypeScript when installing packages from npm often requires you to install related definition ...

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

  4. [TypeScript] Understanding Generics with RxJS

    Libraries such as RxJS use generics heavily in their definition files to describe how types flow thr ...

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

  6. JavaScript Libraries In A TypeScript Application, Revisited

    If you haven’t already gotten involved with it, you’ll probably know that TypeScript is becoming inc ...

  7. 基于Typescript和Jest刷题环境搭建与使用

    写在前面 前几个月在公司用vue3和ts写项目,想巩固一下基础,于是我想起了去年基于JavaScript和Jest搭建的刷题环境,不如,给它搞个加强版,结合Typescript和Jest 搞一个刷题环 ...

  8. Embed dll Files Within an exe (C# WinForms)—Winform 集成零散dll进exe的方法

    A while back I was working on a small C# WinForms application in Visual Studio 2008. For the sake of ...

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

随机推荐

  1. oracle 报“无效数字”异常和“ORA-01830: 日期格式图片在转换整个输入字符串之前结束”

    1.问题1 执行下列SQL: sql = "select count(1) as totle from vhl_model_data a where a.OBTAIN_CREATE_TIME ...

  2. [BZOJ 2048] [2009国家集训队]书堆 【调和级数】

    题目链接:BZOJ - 2048 题目分析 只有一本书时,这本书的重心落在桌子边缘上,伸出桌面的长度就是 1/2. 有两本书时,第一本书的重心就落在第二本书的边缘上,两本书的重心落在桌子边缘上,两本书 ...

  3. Word添加带圈文字

    这个在项目有编号李没有,只能一个一个输入 A.开始------------字体里选择带圈的字符号 B.插入,符号里选编号

  4. 基于opencv的小波变换

    基于opencv的小波变换 提供函数DWT()和IDWT(),前者完成任意层次的小波变换,后者完成任意层次的小波逆变换.输入图像要求必须是单通道浮点图像,对图像大小也有要求(1层变换:w,h必须是2的 ...

  5. CISCO2691的OSPF点对点密文测评测试

    都差不多,粘一个文件就能说明问题了. Router#show run Building configuration... Current configuration : bytes ! version ...

  6. UML 中关系详解以及在visio中的表示

    http://www.cnblogs.com/kittywei/archive/2013/05/15/3079536.html

  7. TF卡的Class4/Class6/Class10

    TF卡全称TransFlash卡,即T-Flash又称MicroSD,随设备微型化的需要,TF卡用途越来越广,速度也越来越快,从最初的Class2早已发展到目前主流的Class10,TF卡体积为15m ...

  8. Spring 通过工厂方法(Factory Method)来配置bean

    Spring 通过工厂方法(Factory Method)来配置bean 在Spring的世界中, 我们通常会利用bean config file 或者 annotation注解方式来配置bean. ...

  9. 【HDOJ】4585 Shaolin

    Set可解,Treap也可解.(1) Treap /* */ #include <iostream> #include <string> #include <map> ...

  10. Learning WCF Chapter1 Creating a New Service from Scratch

    You’re about to be introduced to the WCF service. This lab isn’t your typical “Hello World”—it’s “He ...