Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
denis-migdal opened this issue Feb 23, 2025 · 1 comment

Comments

@denis-migdal
Copy link

πŸ”Ž 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 {}
@MartinJohns
Copy link
Contributor

Duplicate of #36060.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants