Skip to content

error TS2385: Overload signatures must all be public, private or protected. Why? #7577

Closed
@0815fox

Description

@0815fox
public myMethod();
private myMethod(Data?:T,FromRevision?:number,TilRevision?:number);
public myMethod(Data?:T,FromRevision:number=0,TilRevision:number=0) {
  ...
}

gives:

error TS2385: Overload signatures must all be public, private or protected.

What is this restriction needed for? Of course a possible workaround is an internal helper function:

private myMethodInternal(Data?:T,FromRevision:number=0,TilRevision:number=0) {
  ...
}

public myMethod() {
  this.myMethodInternal();
}

But it is just unnecessary work and unnecessary function calls (performance, when called often).
Even worse, when i try to do this on a constructor, it complains:

error TS1089: 'private' modifier cannot appear on a constructor declaration.

Why not? I wanted to have a constructor, which is only accessible by methods inside the class and allows to specify additional parameters to the constructor, which would else hold their default values. Of course, the workaround above also works in this situation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions