evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.98k stars 1.14k forks source link

Generate TypeScript declarations files for TypeScript projects with isolatedDeclarations enabled #3775

Open MichaelMitchell-at opened 4 months ago

MichaelMitchell-at commented 4 months ago

Based on @evanw's comment here, it sounded like ESBuild supporting declaration files is something that's not out of the question, so I'm formally raising a feature request.

Why now Isolated declarations has been implemented in TypeScript 5.5, currently in beta. The nightly build of TypeScript also supports a new compiler API to emit declaration files without performing typechecking, which could be used as a reference. Some aspects of the behavior are still under consideration, like what are and aren't code patterns that a non-type-aware tool could reasonably generate types for. I think it would be valuable for tool developers like @evanw to provide input, especially early on in the process, to help solidify the specification and minimize the chance for backward incompatibles changes needed to be made after TypeScript 5.5 is generally available.

Who benefits Large, composite TypeScript projects benefit from isolated declarations. We've been testing this API at Airtable and I think we can now say that this functionality is usable in a production environment, albeit with some rough edges. We've already started integrating isolated declarations into our CI pipeline, and using a custom parallel TypeScript runner, have seen a ~20% reduction in typechecking times, which will only grow as we enable isolated declarations for more projects. I'm aware of a handful of companies so far that have expressed interest in using and or have already started contributing to isolated declarations: Airtable, Figma, Bloomberg, Google, and Shopify(?).

Why ESBuild Using the tsc-based API to emit declaration files still takes on the order of seconds for larger TypeScript projects, which can add up. ESBuild has proven itself to be a fast and well-tested tool and there isn't really any other tool we'd rather use.