TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Problem with .d.ts file generation for inner classes

Open Velover opened this issue 1 year ago • 4 comments

For the situations where the sub-class should return itself in the callback, it generates the wrong type. It also generates a duplicate definition.

https://www.typescriptlang.org/play/?#code/MYGwhgzhAEAqCmEAu0DeAoaXrLEglsNAEICu+IAJvAE7QC80okMG27OSeh0AwjfDzwAFAEo0mDlIFJSNAHbR58AO7QkAC3wQxAbklSAvgY4AFGvnlIAEvBAgA9mIlTp8WQvVaI+19GMm7OaWSADiDg6UAEYAniLibH7YMnKKmtq+rsZ+oe4AcqQAtlG0zolJ0CmeAKyZRiaG+iYAsu4akQCMYuUcwA7yEA4g8AB0jgDmwgBEHVOidRxVad4N6C1tkQBM3YHYfQNDoxPTm3ML7EteGasmAGKW2ho7fpcAzAvGAQjII2QU1DQRvxBEh4iNglZbPYnKJwRYrOFIrEwbkkAViqV5kA

class Test {
    static Builder = class {
        static Create() {
            return new this();
        }
        PrintHello() {
            return this;
        }

        PrintGoodbye() {
            return this;
        }
        GetNumber() {
            return 5;
        }
    };

    Method1(){
        console.log("1");
        return this
    }
}

expected behaviour generates .d.ts like/ or something like

declare class Anonymous1 {
    static Create(): Anonymous1
    PrintHello(): this;
    PrintGoodbye(): this;
    GetNumber(): number;
}
declare class Test {
    static Builder: Anonymous1;
    Method1(): this;
}

got

declare class Test {
    static Builder: {
        new (): {
            PrintHello(): any;
            PrintGoodbye(): any;
            GetNumber(): number;
        };
        Create(): {
            PrintHello(): any;
            PrintGoodbye(): any;
            GetNumber(): number;
        };
    };
    Method1(): this;
}

Some of the tooling relies on the type generation e.g. roblox-ts and it causes some problems with the package Intellisense because any cannot be used for the generation of code like luau

Velover avatar Jun 30 '24 13:06 Velover

i didn't add the duplicate label, it happened automatically

there are no duplicates of this...

Velover avatar Jun 30 '24 13:06 Velover

It’s because you used the issue template for 9998 duplicates, this isn’t that (did the read the text in the template before you deleted it?). In fact there are no callback functions here

fatcerberus avatar Jun 30 '24 13:06 fatcerberus

https://github.com/microsoft/TypeScript/issues/52415 is very similar but not an exact duplicate. See also https://github.com/microsoft/TypeScript/pull/41587 which is probably what's needed to fix this.

fatcerberus avatar Jun 30 '24 14:06 fatcerberus

It’s because you used the issue template for 9998 duplicates, this isn’t that (did the read the text in the template before you deleted it?). In fact there are no callback functions here

Is that a problem? If so can I fix it? I just got a little confused with these templates and picked the one that was the closest to the issue

Velover avatar Jun 30 '24 14:06 Velover

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

typescript-bot avatar Jul 03 '24 01:07 typescript-bot