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

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

Closed
Howard-Lam-UnitedVanning opened this issue Apr 24, 2024 · 2 comments

Comments

@Howard-Lam-UnitedVanning
          Are you sure? I mean, there is lots of stuff, which is just a design time illusion. What I would like to achieve with that is, that tsc checks, that I can only call public signatures from outside of a class, while I can also call private signatures from inside the class and protected ones from inside a child class.

Originally posted by @0815fox in #7577 (comment)

export default class NetworkService<R, G = undefined, Q = G, D = Q, RD=R> {
  get(query?: Q|null): Promise<AxiosResponse<R>>
  get(param: G|null, query: Q|null): Promise<AxiosResponse<R>>;
  protected get(param?: G|Q|null, query?: Q|null): Promise<AxiosResponse<R>>;
  async get(params?: G|Q|null, query?: Q|null): Promise<AxiosResponse<R>> {
  }
 }
 export default class FCNetworkService<R, G=undefined, Q=G, D=Q, RD=R> extends NetworkService<R,G,Q,D,RD> {
    override async get(params?: G|Q|null, query?: Q|null) {
        const result = await super.get(params, query);
    }
}

If I don't add an extra line

get(param?: G|Q|null, query?: Q|null): Promise<AxiosResponse<R>>;

I get the error
"Argument of type 'G | Q | null | undefined' is not assignable to parameter of type 'G | null'."

But that function signature should not be ever called from the outside because the function body cannot tell if params is actually a query object if the second input is undefined, which is why I have the restriction on the second overlord. That is why I need protected for the third overload.

@Howard-Lam-UnitedVanning Howard-Lam-UnitedVanning changed the title Are you sure? I mean, there is lots of stuff, which is just a design time illusion. What I would like to achieve with that is, that tsc checks, that I can only call public signatures from outside of a class, while I can also call private signatures from inside the class and protected ones from inside a child class. error TS2385: Overload signatures must all be public, private or protected. Apr 24, 2024
@RyanCavanaugh
Copy link
Member

It looks like this is a question rather than a bug report. This issue tracker is for tracking bugs and active work on TypeScript itself, rather than a general forum for programmers using TypeScript to get help or ask questions.

You can ask questions on sites like Stack Overflow. We are not able to provide one-on-one support on the issue tracker. Please read the issue template carefully - it has important information on what kinds of reports can be acted on here, as well as links to useful TypeScript resources. Thanks!

@RyanCavanaugh RyanCavanaugh closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2024
@Howard-Lam-UnitedVanning
Copy link
Author

Howard-Lam-UnitedVanning commented Apr 25, 2024

It looks like this is a question rather than a bug report. This issue tracker is for tracking bugs and active work on TypeScript itself, rather than a general forum for programmers using TypeScript to get help or ask questions.

You can ask questions on sites like Stack Overflow. We are not able to provide one-on-one support on the issue tracker. Please read the issue template carefully - it has important information on what kinds of reports can be acted on here, as well as links to useful TypeScript resources. Thanks!

It isn't a question but that overload signatures currently must all have the same access level but it was asked before to allow different access level and I'm providing a use case for it.

The original post was closed and I could not reply to it, so I had to reply to it in a new issue.

EDIT: never mind this. Rather than having a new issue as a reply to the original issue, I have posted another feature request here #58316

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