unbuild icon indicating copy to clipboard operation
unbuild copied to clipboard

Re-exporting types from another package are not properly marked as type-only export in declaration file.

Open NamesMT opened this issue 1 year ago • 4 comments

Environment

Both unbuild@latest (2) and unbuild@rc (3rc7) NodeJS 20

Reproduction

https://github.com/NamesMT/sencrypt

Describe the bug

I am trying to re-export the class SHash as a type-only export:

export type { SHash } from '@namesmt/shash'

// Also tried this syntax:
export { type SHash } from '@namesmt/shash'

But the index.d.mts declaration result is:

export { SHash } from '@namesmt/shash';

Which is not correct and in the IDE of the end-user it seemed like they could import and use SHash as a class, but it will error at runtime.

Additional context

No response

Logs

No response

NamesMT avatar Jul 25 '24 14:07 NamesMT

Refer to source, unbuild use rollup-plugin-dts to generate d.ts.

So it is a issue of rollup-plugin-dts. Consider the plugin has been in Maintenance Mode, maybe it will be a long time to resolve it...

s3xysteak avatar Aug 05 '24 06:08 s3xysteak

I have a simular issue. my dts generated a _mergeNamespaces function, which just a "any" wrap 🤔

source:

export * as Rx from 'rxjs'

generated:

import * as rxjs from 'rxjs';

function _mergeNamespaces(n, m) {
  m.forEach(function (e) {
    e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
      if (k !== 'default' && !(k in n)) {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  });
  return Object.freeze(n);
}

var rx = /*#__PURE__*/_mergeNamespaces({
  __proto__: null
}, [rxjs]);

export { rx as Rx };

cangSDARM avatar Oct 17 '24 05:10 cangSDARM

So it is a issue of rollup-plugin-dts. Consider the plugin has been in Maintenance Mode, maybe it will be a long time to resolve it...

How about trying rollup-plugin-flat-dts?

gxres042 avatar Jan 20 '25 02:01 gxres042

Upstream issue: https://github.com/Swatinem/rollup-plugin-dts/issues/311 and should be resolved by pr: https://github.com/Swatinem/rollup-plugin-dts/pull/333 (merged but not released yet ⌛)

kricsleo avatar Feb 07 '25 02:02 kricsleo