Skip to content

Declaration emit contains trivial local duplicatesΒ #51610

Open

Description

Bug Report

πŸ”Ž Search Terms

declaration emit dts inline inlining duplication

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

export const I = {
    /**
     * Docs
     */
    prop: true
};

export const Inlined           = I;
export const Aliased: typeof I = I;

πŸ™ Actual behavior

Declaration emit contains a duplicated type.

export declare const I: {
    /**
     * Docs
     */
    prop: boolean;
};
export declare const Inlined: {
    /**
     * Docs
     */
    prop: boolean;
};
export declare const Aliased: typeof I;

πŸ™‚ Expected behavior

Declaration emit should reference the original via an alias.

export declare const I: {
    /**
     * Docs
     */
    prop: boolean;
};
export declare const Inlined: typeof I;
export declare const Aliased: typeof I;

Notes

I know this is working-as-expected so feel free to close immediately if there is no quick win in sight.

We've got a bunch of documentation that has bloated declarations because of this specific trivial intra-file variant of the more generalized duplication/inlining issue. It happens when we do renames or migrations of types from one name to another and they need to be exported under separate names. The workaround is to explicitly add the typeof X annotation but folk forget this.

The general solution long-term will be to go with --isolatedDeclarations and a completely different form of declaration emit, but in the short-term, and for folks that enjoy inference, maybe there's also a possibility to quickly fix up existing declaration emit for this specific case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Experimentation NeededSomeone needs to try this out to see what happensSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions