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

Implement an abstract class that contains protected abstract methods #32292

Closed
Shinigami92 opened this issue Jul 8, 2019 · 5 comments
Closed
Labels
Question An issue which isn't directly actionable in code

Comments

@Shinigami92
Copy link

Code

export abstract class MyLifecycleHook {
   protected abstract aMethod(a: number, b: string): void | Promise<void>;
}

export default class MyClassA implements MyLifecycleHook {
   protected aMethod(a: number, b: string): void | Promise<void> {
      // Code
   }
}

export default class MyClassB implements MyLifecycleHook {
   public aMethod(a: number, b: string): void | Promise<void> {
      // Code
   }
}

Playground

Expected behavior:
It should be protectable.
Alternative: It should at least be made publicable.

Actual behavior:

Property 'aMethod' is protected but type 'MyClassA' is not a class derived from 'MyLifecycleHook'.

Related Issues:
#25163

@Shinigami92 Shinigami92 changed the title Extend from abstract class that contains protected abstract methods Implement an abstract class that contains protected abstract methods Jul 8, 2019
@AlCalzone
Copy link
Contributor

@Shinigami92
Copy link
Author

No, I only reduced my code.
So I need to extend from a base class: updated Playground

@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 added the Question An issue which isn't directly actionable in code label Jul 8, 2019
@Shinigami92
Copy link
Author

First of all, I've already searched StackOverflow and come from there.
Besides, I of course read through the templates and just did not know if this was a bug or a feature that could be enabled.
That's why I have not explicitly asked a question!

An interface can't have member access. That's clear and it's alright, other languages work the same way.
But TypeScript can also be implement an abstract class and treat it as interface.

But the following isn't working: PlayGround

Maybe the Handbook isn't clear enough.
Handbook Classes: Using a class as an interface

It's a bug(/feature request) if you aren't allowed to use classes as interfaces that contains private/protected members.
Please update the Handbook and/or make the compiler message clearer.

It's a feature request if you should be able to use classes as interfaces and only ignore private/protected methods or you are able to use the member access or upper member access (protected can also be upgraded to public, like extending it).
We should maybe define a proposal?

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants