unbuild icon indicating copy to clipboard operation
unbuild copied to clipboard

feat: experimental isolated declaration support

Open pi0 opened this issue 1 year ago • 0 comments

Add experimental support for isolated declaration generation powered by OXC and unplugin-isolated-decl by @sxzz ❤️

Read more: https://github.com/microsoft/TypeScript/issues/58944

To opt in:

import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
  rollup: {
    // https://github.com/microsoft/TypeScript/issues/58944
    // https://github.com/unplugin/unplugin-isolated-decl
    isolatedDecl: {
      transformer: "oxc",
    },
  },
});

Tips for migrating the codebase to be ready for isolated declaration support:

  • ts-fix might help. (you can try with npx @pi0/[email protected] -w - see https://github.com/microsoft/ts-fix/issues/29)
  • Using @typescript-eslint/explicit-function-return-type is helpful to find all issues (#412)
  • Using transformer: "typescript" might help to find issues easier. Default oxc sometimes is crypted about which line.

TODO

Currently plugin generates types to dist/src/**.{mts,cts}. We need to find a way to merge them or at least generate top level declaration in dist/*.{mts,dts} to make it cleaner for package.json exports and avoid requirement of updating it. Also the paths seem relative to root in tsconfig rather than dist!

pi0 avatar Jul 02 '24 12:07 pi0