-
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
Argument of type 'this' is not assignable to parameter of type 'this'. #5449
Comments
|
@vladima Don't know why no.2 is causing the same error but I did more test with the latest "next" release and found the actual issue: class Test<TSample> {
// this is the property triggering the issue.
sample: TSample;
constructor() { }
}
class Sample {
constructor(
public host: Test<this>
) { }
}
class TerminalSample extends Sample {
constructor(host: Test<this>) {
super(host);
}
} |
here is a simpler example: class Base {
constructor(a: this) { }
}
class Derived extends Base {
prop: string;
}
var base: Base;
var derived: Derived;
new Base(base); // Error should be OK
new Derived(derived); // Error should be OK
new Derived(base); // Error |
The bug here is that the |
@sandersn can you add the error check for release-1.7 |
There is an existing error for this, it's just getting missed now. I'll figure out why. |
@sandersn The issue is in the |
So I just made my use case dead? I don't understand why we need to disallow |
@vilic The use case was dead all along, we just weren't reporting an error properly. The compiler isn't equipped to handle |
@ahejlsberg It's actually quite like what I wrote, more specifically: abstract class Test<TSample> {
sample: TSample;
}
class SomeTest extends Test<SomeSample> {
}
abstract class Sample {
constructor(
public host: Test<this>
) { }
}
class SomeSample extends Sample {
constructor(host: Test<this>) {
super(host);
host.sample = this;
}
}
let someTest = new SomeTest<SomeSample>();
let someSample = new SomeSample(someTest);
someTest.host.sample; // expecting type `SomeSample`. Actually I ended up with another implementation (as this is messing things up), but I think the scenario should be reasonable. I didn't realize that constructors have different contexts than other instance methods, but certainly it could wait long enough if it's not something trivial to do. |
This error also appears on generics with
this
to thesuper
call (which is the real use case).The text was updated successfully, but these errors were encountered: