Skip to content

Private and protected modifiers are removed without error in declaration emit if class expression is passed through a generic functionΒ #42499

Closed
@dragomirtitian

Description

@dragomirtitian

Bug Report

πŸ”Ž Search Terms

class expressions private protected declaration
mixins private protected declaration

πŸ•— Version & Regression Information:

  • This is the behavior in every version I tried 3.3 - 4.2@beta

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare function mix<TMix>(mixin: TMix): TMix;

const DisposableMixin = class {
    protected _onDispose() {
        this._assertIsStripped()
    }
    private _assertIsStripped() {
    }
};

// Expected error since declaration is not representable 
// export const DisposableMixinError =  mix(DisposableMixin);

// No error, but definition is wrong. 
export default mix(DisposableMixin);
export class Monitor extends mix(DisposableMixin) {
    protected _onDispose() {
    }
}

πŸ™ Actual behavior

Emitted declaration erases private and protected modifiers on DisposableMixin. This actually generates a ts error in the declaration of Monitor on the _onDispose override, since the method has a more restrictive modifier than the emitted declaration for the base class.

declare const _default: {
    new (): {
        _onDispose(): void;
        _assertIsStripped(): void;
    };
};
export default _default;
declare const Monitor_base: {
    new (): {
        _onDispose(): void;
        _assertIsStripped(): void;
    };
};
export declare class Monitor extends Monitor_base {
    protected _onDispose(): void;
}

Playground Link

πŸ™‚ Expected behavior

An error on the exported private and protected members (like what happens if you uncomment DisposableMixinError ):

Property '_onDispose' of exported class expression may not be private or protected.(4094)
Property '_assertIsStripped' of exported class expression may not be private or protected.(4094)

Note

This issue might be made moot by #41581 in 4.3, or later, depending when declaration emit will be changed to use typeof class

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions