-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Assigning to Partial<this>
inside the child class leads to error
#24946
Comments
Well, I think this one is tricky. This is what I have learned from polymorphic Working caseThe first use-case of polymorphic class A {
method1(): this {
return this // <-- Assignable
}
method2(): this {
return new A() // <-- Not assignable
}
}
class B extends A {
prop1: number
// method1(): this { <-- 'this' type becomes B
// return this <-- 'this' instance is B, B is assignable to B
// }
// method2(): this {
// return new A() <-- 'this' instance is B, A isn't assignable to B
// (A doesn't have prop1, but B has)
// }
}
|
Duplicate of #13442. |
@mhegazy |
TypeScript Version: 3.0.0-dev.20180609
Search Terms: polymorphic
this
,Partial
Code
Expected behavior:
No error should occur here.
As there is no error in this code below. (append this to the previous snippet)A better opinion is available at the next comment.
Actual behavior:
Playground Link: Playground · TypeScript
Related Issues:
I'm not sure, but this looks similar to me: #22934
Thank you very much.
The text was updated successfully, but these errors were encountered: