parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.27k stars 2.26k forks source link

Supports typing generation for multiple targets #9816

Open ocavue opened 1 week ago

ocavue commented 1 week ago

🙋 feature request

I'd love to generate multiple .d.ts files for multiple targets.

🤔 Expected Behavior

A library could have multiple entry points, like my-pkg/client and my-pkg/server. In such case, it should have multiple type declaration files, like dist/client.d.ts and dist/server.d.ts.

😯 Current Behavior

parcel only supports generate one .d.ts file from the types field in package.json according to the docs.

When building a library, Parcel can extract the types from your entry point and generate a .d.ts file. Use the types field in package.json alongside a target such as main or module to enable this.

{
  "source": "src/index.ts",
  "module": "dist/index.js",
  "types": "dist/index.d.ts"
}

💁 Possible Solution

Maybe we can add types to targets

{
  "targets": {
    "server": {
+     "types": "./dist/server.d.ts",
      "source": "./src/server.ts"
    },
    "client": {
+     "types": "./dist/client.d.ts",
      "source": "./src/client.ts"
    }
  },
}

🔦 Context

N/A

💻 Examples

N/A