Re-exporting types from another package are not properly marked as type-only export in declaration file.
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
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...
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 };
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?
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 ⌛)