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

[bug] Changes type to reference to the wrong variable #323

Open
nicolo-ribaudo opened this issue May 8, 2024 · 2 comments
Open

[bug] Changes type to reference to the wrong variable #323

nicolo-ribaudo opened this issue May 8, 2024 · 2 comments
Labels
Milestone

Comments

@nicolo-ribaudo
Copy link

nicolo-ribaudo commented May 8, 2024

Bug report

Input code

// index.ts
import { fn } from "./other-file";
export function a() {}
a.fn = fn;
// other-file.ts
export function fn() {}

Actual output

// Generated by dts-bundle-generator v9.5.1

declare function fn(): void;
export declare function a(): void;
export declare namespace a {
	var fn: typeof fn;
}

export {};

Notice that the type of var fn refers to var fn and not to function fn

Expected output

Maybe this?

// Generated by dts-bundle-generator v9.5.1

declare function fn(): void;
type fn_type = typeof fn;
export declare function a(): void;
export declare namespace a {
	var fn: fn_type;
}

export {};

or this

// Generated by dts-bundle-generator v9.5.1

declare function fn$1(): void;
export declare function a(): void;
export declare namespace a {
	var fn: typeof fn$1;
}

export {};

Additional context

This also happens in rollup-plugin-dts

@timocov timocov added the Bug label May 8, 2024
@timocov timocov added this to the 9.6 milestone May 8, 2024
@timocov
Copy link
Owner

timocov commented Jun 15, 2024

So the issue is that the compiler generates dts like so:

export declare function a(): void;
export declare namespace a {
    var fn: typeof import("./other-file").fn;
}

And then the tool traverse this and removes all dynamic imports of local files (it happens here) and resolves the name on the right with its registered "local" name. The issue is that the tool doesn't consider any names declared in namespaces thus fn stays fn, not being renamed to something fn$1 or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants