Search code examples
javascripttypescripttypescript-typingsparceljs

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. Here is my configuration in 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:

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.


Solution

  • It looks like your issue is caused by the the "incremental": true line in your tsconfig.json's "compilerOptions" (see here). If you remove this line, parcel should generate .d.ts files as expected.

    (In an ideal world, parcel should be able to handle this case - I filed this bug with parcel to report the problem - and this PR to fix it).