Skip to content

Problem with .d.ts file generation for inner classes #59079

Closed as not planned
Closed as not planned
@Velover

Description

@Velover

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions