Skip to content

A solution to Property of exported anonymous class type may not be private or protected.Β #61249

@denis-migdal

Description

@denis-migdal

πŸ”Ž Search Terms

Property of exported anonymous class type may not be private or protected

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________

⏯ Playground Link

No response

πŸ’» Code

export function foo() {

        return class X {
                protected foo() {}
        }
}

πŸ™ Actual behavior

test.ts:1:17 - error TS4094: Property 'foo' of exported anonymous class type may not be private or protected.

1 export function foo() {
                  ~~~


Found 1 error in test.ts:1

πŸ™‚ Expected behavior

In the .d.ts file, just add a temporary class to remove this bug...

Additional information about the issue

This bug was signaled ~6 years ago, but was closed: #30355

The following works:

class X {
        protected foo() {}
}

export function foo() {

        return X;
}

It produces this .d.ts :

declare class X {
    protected foo(): void;
}
export declare function foo(): typeof X;
export {}

So for our case, just create a temporary class outside of foo() and use it...

declare class foo__internals__X {
    protected foo(): void;
}
export declare function foo(): typeof foo__internals__X;
export {}

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