![](/img/trans.png)
[英]How do I handle TypeScript type definitions across many Visual Studio (2013) projects?
[英]How do I share many Typescript interfaces across projects
我做了一個僅包含打字稿界面的項目。 所以我可能有諸如account.ts和item.ts之類的文件,它們僅包含接口
export interface Account
{
name: string;
}
我該如何在本地打包所有這些文件,以便我可以從本地npm安裝(並從本地)使用那些接口,例如...
import { Account, Item } from 'all-my-interfaces';
僅需基本知識的快速演練:
> mkdir my-lib
> cd my-lib
> npm init -y
> npm i -D typescript
> touch tsconfig.json
> mkdir src
> touch src/index.ts
> touch .npmignore
tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"declaration": true,
"outDir": "./dist",
"strict": true
}
}
SRC / index.ts:
export interface Check {
isValid(): bool;
}
.npmignore:
dist/
在package.json中添加npm腳本:
"prepublishOnly": "tsc"
發布:
npm publish
現在在其他項目中使用:
npm i my-lib
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.