-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Interfaces extending class with private props #6333
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
Comments
Possible solutions:
|
Note: Could this be a bug in TS? |
I totally agree that tokens should be exporting explicit interfaces, not interfaces derived from implementation classes. |
Putting as 1.0 since a stable extension API is one of our goals for 1.0. |
TS magic: type PublicShape<T> = Pick<T, keyof T>;
export interface IInterface extends PublicShape<CClass> {}; |
|
According to the issue here: microsoft/TypeScript#31299 However, I am not certain if this is documented, or just "current behavior". |
Ah, I think it is much clearer if pure interfaces are the explicit public contract, and implementation classes always implement the token interfaces. |
Note: It seems super weird to me the interface picks up the private properties of the class, since declaring a private property on an interface gives a compile error. This is why I'm wondering if this is a TS bug. |
Can you make a list of the token interfaces derived from implementation classes? I don't think this is a widespread problem - I think most places tokens are typed with pure interfaces. |
Sounds like a good issue to file with them. |
Xref: microsoft/TypeScript#471 |
microsoft/TypeScript#18499 has some relevant discussion as well. |
I think this is simply a quirk we will have to work around, given that Note: Some places in the Lab code, this behavior is probably what we want. E.g. export interface IShell extends Widget { ... } Here, I think we definitely want to ensure that a replacement of |
My conclusion here: We should only use the |
Current interfaces (mainly tokens) that should have a closer look:
I don't know how the Recommendation: Extract the interface of all tokens, and revert the logic (interface declaration is explicit, and class |
IMO, I don't think we ever should explicitly expect a subclass at the token level, only potentially within our own class hierarchies. |
Current tokens that
|
Note: I can do the legwork here, but I need input on:
|
|
@blink1073 For the three Widget/token mixes outlined above, would you say that it makes sense to have the requirement that the provided object subclasses |
I think it is okay to assume |
👍 for what @jasongrout said |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related discussion. |
Describe the bug
When working on #6302, I tried to make an extension that would replace the document manager by providing the
IDocumentManager
token. So I make a new class that implements the interface, but immediately get hit by the error:It is not an alternative to not declare it, as it will then complain about the missing private property (!).
To Reproduce
Any interface declaration extending a class definition with private properties will throw this error, e.g.:
Expected behavior
Exported interfaces, and especially token interfaces, should not include any private property declaration.
The text was updated successfully, but these errors were encountered: