-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
The private symbol property leads a conflict with the implemented interface. #26206
Comments
This is a correct error, oddly enough. Here's a simplified example that still shows the error: type F<T> = (this: T) => void;
interface IClassA {
hello(): F<this>;
}
class A implements IClassA {
p1: string = '';
public hello(): F<this> {
return null as any;
}
}
Again, oddly, class A implements IClassA {
p1: string = '';
public hello(): F<this> {
return () => {
console.log(this.p1.toLowerCase());
}
}
}
let a: IClassA = new A();
let bad: IClassA = { hello: a.hello };
// Runtime error!
bad.hello(); The fix is to specify the type parameter of type F<T> = (this: T) => void;
interface IClassA {
hello(): F<this>;
}
class A implements IClassA {
p1: string = '';
public hello<T extends IClassA>(this: T): F<T> {
return () => {
// Would be an error to write this now:
// console.log(this.p1.toLowerCase());
}
}
}
let a: IClassA = new A();
let notbad: IClassA = { hello: a.hello };
// OK
notbad.hello(); |
Emmmmm, thx for replying.... My question is:
And the error means |
|
TypeScript Version: v3.1.0-dev.20180804
Search Terms: private symbol property this generic parameter
Code
Expected behavior:
I think it should work well without any error reporting.
Actual behavior:
It reports an error like this:
[p1
is a private property of the class, how could it lead a conflict with an implemented interface?Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: