Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
NamesMT opened this issue Jul 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@NamesMT
Copy link

NamesMT commented Jul 25, 2024

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 NamesMT added the bug Something isn't working label Jul 25, 2024
@s3xysteak
Copy link
Contributor

s3xysteak commented Aug 5, 2024

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...

@cangSDARM
Copy link

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 };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants