镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Closed as not planned
Closed as not planned

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

Activity

  1. Velover commented on Jun 30, 2024

    @Velover
    Author

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

    there are no duplicates of this...

  2. fatcerberus commented on Jun 30, 2024

    @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

  3. fatcerberus commented on Jun 30, 2024

    @fatcerberus

    #52415 is very similar but not an exact duplicate.
    See also #41587 which is probably what's needed to fix this.

  4. Velover commented on Jun 30, 2024

    @Velover
    Author

    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

  5. typescript-bot commented on Jul 3, 2024

    @typescript-bot
    Contributor

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

  6. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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