You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Typescript 1.6.2
When trying to implement a class with private variables complier wants the derived class to implement the parent's private variables.
export class Father {
private hidden: string;
public visible: string;
}
export class Child implements Father{
public visible: string;
}
(7,15): error TS2420: Class 'child' incorrectly implements interface 'father'.
Property 'hidden' is missing in type 'child'.
Trying to do the wrong thing and do implement the private variable results in the compiler not happy since we implement a private variable of the parent (In a typed language this is wrong as well, but in JS it might be a good catch...)
export class Father {
private hidden: string;
public visible: string;
}
export class Child implements Father{
private hidden: string;
public visible: string;
}
(7,15): error TS2420: Class 'child' incorrectly implements interface 'father'.
Types have separate declarations of a private property 'hidden'.
The text was updated successfully, but these errors were encountered:
the issue here is the private property declaration. When implementing a class with private, the implementing class gets the property declaration but not its implementation. private members can not be re-implemented, the only allowed implementation for them is their original declaration. so now you have a class is not implementable.
for mix-in patterns, do not use private members, or split your non-private declarations in an interface and use that.
Hi,
Typescript 1.6.2
When trying to implement a class with private variables complier wants the derived class to implement the parent's private variables.
(7,15): error TS2420: Class 'child' incorrectly implements interface 'father'.
Property 'hidden' is missing in type 'child'.
Trying to do the wrong thing and do implement the private variable results in the compiler not happy since we implement a private variable of the parent (In a typed language this is wrong as well, but in JS it might be a good catch...)
(7,15): error TS2420: Class 'child' incorrectly implements interface 'father'.
Types have separate declarations of a private property 'hidden'.
The text was updated successfully, but these errors were encountered: