timocov / dts-bundle-generator

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

Incorrect handling of duplicates in augmented types #335

Open mnaoumov opened 2 hours ago

mnaoumov commented 2 hours ago

Bug report

obsidian library has type Plugin

HTML DOM API also has deprecated type Plugin

It seems dts-bundle-generator trying to avoid confusion between those two Plugin types replaces the one we use with Plugin$1, but this makes the augmentation incorrect, because there aliases are not supported

Input code

import { Plugin } from 'obsidian';

export interface Plugin2 extends Plugin {}

declare module 'obsidian' {
    interface Plugin {
        someProperty: string;
    }
}

Expected output

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

import { Plugin } from 'obsidian';

export interface Plugin2 extends Plugin {
}
declare module "obsidian" {
    interface Plugin {
        someProperty: string;
    }
}

export {};

Actual output

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

import { Plugin as Plugin$1 } from 'obsidian';

export interface Plugin2 extends Plugin$1 {
}
declare module "obsidian" {
    interface Plugin$1 {
        someProperty: string;
    }
}

export {};

Additional context Add any other context about the problem here (CLI options, etc)

mnaoumov commented 2 hours ago

Even more, if you have a manual alias

import { Plugin as SomeAlias } from 'obsidian';

export interface Plugin2 extends SomeAlias {}

declare module 'obsidian' {
    interface Plugin {
        someProperty: string;
    }
}

it incorrectly renames the augmented interface

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

import { Plugin as SomeAlias } from 'obsidian';

export interface Plugin2 extends SomeAlias {
}
declare module "obsidian" {
    interface SomeAlias {
        someProperty: string;
    }
}

export {};