简体   繁体   English

Parcel 不会为 TypeScript 库生成类型声明

[英]Parcel does not generate type declarations for a TypeScript library

I just started using Parcel and I have this issue, where it is not generating type declarations and emits an empty index.d.ts file instead.我刚开始使用 Parcel,我遇到了这个问题,它没有生成类型声明,而是发出一个空的index.d.ts文件。 Here is my configuration in package.json :这是我在package.json中的配置:

{
  // ...
  "scripts": {
    "prepare": "yarn build",
    "check": "tsc --noEmit",
    "watch": "parcel watch --no-source-maps --no-cache",
    "build": "parcel build --no-source-maps --no-cache"
  },
  "main": "./lib/index.js",
  "source": "./src/index.ts",
  "types": "./lib/index.d.ts",
  "module": "./lib/esm/index.js",
  "devDependencies": {
    "@parcel/packager-ts": "^2.0.1",
    "@parcel/transformer-typescript-types": "^2.0.1",
    "@types/node": "^16.11.9",
    "parcel": "^2.0.1",
    "typescript": "^4.5.2"
  },
  // ...
}

And here is a simple example of an type that I have defined in my code:这是我在代码中定义的type的简单示例:

export type Response = {
  /**
   * The list of added/removed hashes
   */
  hashes: string[];
  /**
   * The list of skipped hashes
   */
  skipped: string[];
};

Any ideas why this is happening?任何想法为什么会发生这种情况? Have I configured something incorrectly?我是否配置错误? I have followed this documentation.我已遵循文档。

Thank you.谢谢你。

It looks like your issue is caused by the the "incremental": true line in your tsconfig.json 's "compilerOptions" (see here ).看起来您的问题是由tsconfig.json"compilerOptions"中的"incremental": true行引起的(请参见此处)。 If you remove this line, parcel should generate .d.ts files as expected.如果删除此行,parcel 应按预期生成.d.ts文件。

(In an ideal world, parcel should be able to handle this case - I filed this bug with parcel to report the problem - it should be an easy fix). (在理想情况下,parcel 应该能够处理这种情况 - 我用 parcel 提交了这个错误以报告问题 - 这应该是一个简单的修复)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM