博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[TypeScript] Generating Definition Files
阅读量:4347 次
发布时间:2019-06-07

本文共 1702 字,大约阅读时间需要 5 分钟。

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.tsexport * 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.

 

转载于:https://www.cnblogs.com/Answer1215/p/5582616.html

你可能感兴趣的文章
秒杀多线程第四篇 一个经典的多线程同步问题
查看>>
RocketMQ配置
查看>>
关于typedef的用法总结(转)
查看>>
Linux下安装rabbitmq
查看>>
【转】判断点在多边形内(matlab)
查看>>
excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法
查看>>
机器码和字节码
查看>>
【解决Chrome浏览器和IE浏览器上传附件兼容的问题 -- Chrome关闭flash后,uploadify插件不可用的解决办法】...
查看>>
34 帧动画
查看>>
二次剩余及欧拉准则
查看>>
thymeleaf 自定义标签
查看>>
关于WordCount的作业
查看>>
UIView的layoutSubviews,initWithFrame,initWithCoder方法
查看>>
STM32+IAP方案 实现网络升级应用固件
查看>>
用74HC165读8个按键状态
查看>>
jpg转bmp(使用libjpeg)
查看>>
linear-gradient常用实现效果
查看>>
sql语言的一大类 DML 数据的操纵语言
查看>>
VMware黑屏解决方法
查看>>
JAVA 基础 / 第八课:面向对象 / JAVA类的方法与实例方法
查看>>