Skip to content

False error TS4094: ... exported class expression may not be private or protected. #30355

Closed
@a-student

Description

@a-student

TypeScript Version: 3.3.3333

Code

src/test.ts:

export function test () {
    return class {
        private privateMember () {
        }
    };
}

tsconfig.json:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "declaration": true
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}

Expected behavior:
No compilation error.

Actual behavior:
Compiler prints error:
$ tsc
src/test.ts(1,17): error TS4094: Property 'privateMember' of exported class expression may not be private or protected.

Playground Link: not possible to provide.

Workaround

Declare the return type explicitly:

export function test (): new() => Object {
    return class {
        private privateMember () {
        }
    };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions