【问题标题】:Include TypeScript types in TS export在 TS 导出中包含 TypeScript 类型
【发布时间】:2021-09-29 08:57:24
【问题描述】:

我有一个 TypeScript 库,我想将其导出以供其他 JS/TS 开发人员使用。作为对我的图书馆用户的好处,我也想导出这些类型。我怎么做? IE。如何导出index.d.ts 类型声明文件?

我看过TypeScript docs,但他们似乎在谈论编写显式类型声明,而我想在运行npx tsc时自动导出类型声明。

这是tsconfig.json

{
  "compilerOptions": {
    "lib": ["ES2019"],
    "module": "es6",
    "target": "es5",
    "moduleResolution": "node",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "sourceMap": true,
    "outDir": "build",
    "strict": true,
    "noImplicitAny": true,
  },
  "include": ["./**/*.ts"],
  "exclude": ["node_modules", ".vscode", "test"]
}

【问题讨论】:

    标签: typescript


    【解决方案1】:

    有时写出一个问题会告诉你如何自己找到答案:)

    按照CLI docs 中的指定添加--declaration 可以解决问题,即:

    tsc index.js --declaration
    

    【讨论】:

      猜你喜欢
      • 2021-05-10
      • 1970-01-01
      • 2020-06-22
      • 2021-01-11
      • 2021-10-24
      • 2016-10-21
      • 2016-05-31
      • 1970-01-01
      • 2019-05-03
      相关资源
      最近更新 更多