这是indexloc提供的服务,不要输入任何密码
Skip to content

Issue: d.ts file generated by tsup includes incorrect content and loses types (because of _mergeNamespaces) #1351

@liorcohen55551

Description

@liorcohen55551

I am encountering an issue when building TypeScript declaration files (.d.ts) using tsup. Specifically, the generated exports1.d.ts file contains unexpected content, which causes all types to be lost. Below are the files involved and the problem in detail:


Files:

my-exports.ts

export * as Foo from './exports1';

exports1.ts

export * from 'react/experimental';

Problem:

When building the .d.ts files using tsup, the generated exports1.d.ts file contains the following code:

import * as experimental from 'react/experimental';
export * from 'react/experimental';

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 exports1 = /*#__PURE__*/_mergeNamespaces({
  __proto__: null
}, [experimental]);

export { exports1 as e };

The function _mergeNamespaces seems to be causing the issue, where all types are lost in the process.


Image

Expected Behavior:

I expect tsup to generate the .d.ts files without the _mergeNamespaces function and without losing any type information. The file should export types correctly, preserving the structure from the original exports1.ts.

Any Idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions