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
}
}
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:
Use extends not implements.
https://www.typescriptlang.org/docs/handbook/classes.html#inheritance
No, I only reduced my code.
So I need to extend from a base class: updated Playground
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!
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?_
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.