-
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
this
type in constructor interface will not be extended in sub class
#28930
Comments
It works when only interface involves. I don't know if mixing up interface AConstructor {
new (): AInstance
a(): this
}
interface AInstance {
c: string
}
declare const A: AConstructor
declare function test<T extends AConstructor>(a: T): T
interface BConstructor extends AConstructor {
b: string
}
declare const B: BConstructor
const B1: typeof B = B.a() // Good
const B2: typeof B = test(B) // Good |
Maybe it same as this issue #26206 (comment) |
I believe what you really want is #5863. |
I would suggest patching over vuejs/vue#8595 to return |
...like in vuejs/vue#9173 😄 |
Oh, I didn't realize #5863 is related. Thank you for pointing it out and suggestion! |
This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed automatic house-keeping purposes. |
TypeScript Version: 3.3.0-dev.20181208
Search Terms: constructor interface this extends sub class
Code
Expected behavior:
The return type of
B.a()
andtest(B)
istypeof B
.Actual behavior:
The return type of
B.a()
andtest(B)
isAConstructor
.Playground Link:
https://www.typescriptlang.org/play/#src=interface%20AConstructor%20%7B%0D%0A%20%20%20%20new%20()%3A%20AInstance%0D%0A%20%20%20%20a()%3A%20this%0D%0A%7D%0D%0A%0D%0Ainterface%20AInstance%20%7B%0D%0A%20%20%20%20a%3A%20string%0D%0A%7D%0D%0A%0D%0Adeclare%20const%20A%3A%20AConstructor%20%0D%0A%0D%0Adeclare%20function%20test%3CT%20extends%20typeof%20A%3E(a%3A%20T)%3A%20T%0D%0A%0D%0Aclass%20B%20extends%20A%20%7B%0D%0A%20%20%20%20b%3A%20string%0D%0A%7D%0D%0A%0D%0Aconst%20B1%3A%20typeof%20B%20%3D%20B.a()%20%2F%2F%20Unexpected%3A%20Return%20type%20is%20AConstructor%0D%0Aconst%20B2%3A%20typeof%20B%20%3D%20test(B)%20%2F%2F%20Unexpected%3A%20Type%20parameter%20is%20inferred%20to%20AConstructor
Related Issues:
vuejs/vue-class-component#294
Background: I've found this behaviour while investigating the above issue. This is caused by recent changes for Vue's type declaration. It looks like the extending class does not match with the decorator type because
this
type is still base constructor type.I'm still not sure if my guess is correct. If it is not true, please just let me know about that.
The text was updated successfully, but these errors were encountered: