timocov / dts-bundle-generator

A tool to generate a single bundle of dts with types tree-shaking
MIT License
762 stars 40 forks source link

Star-imports don't get included in the bundle #304

Closed pylixonly closed 7 months ago

pylixonly commented 8 months ago

Bug report When star-importing another module import *, the value gets ignored and won't bundle. The following will error out without --no-check:

Input code

// otherLib.ts
export function foo_func() {}
export function bar_func() {}

// index.ts
import * as lib from "./otherLib";
export const Lib = lib;

Expected output(?)

export declare const Lib: {
    foo_func(): void;
    bar_func(): void;
};

export {};

Actual output

// without --no-check: dist/index.d.ts(1,34): error TS2552: Cannot find name 'lib'. Did you mean 'Lib'?
export declare const Lib: typeof lib;

export {};

Additional context This can be work around by "cloning" the imported module with spread operator { ...lib }. Doing this will result the "expected output" shown above.

timocov commented 8 months ago

What version of the tool you're using?

timocov commented 8 months ago

As a workaround for now you can use something like export { lib as Lib }, technically should be around the same. I'll take a look in details later

pylixonly commented 8 months ago

What version of the tool you're using?

From package.json, "dts-bundle-generator": "^9.3.1",

My usage was something along with:

export const getSomething = () => ({
    somethingKey: starImportedModule
})

so that doesn't really work as a workaround in this case

timocov commented 6 months ago

The fix has been published in 9.4.0 version.