-
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
Infer type of method parameter from base class #42953
Infer type of method parameter from base class #42953
Conversation
The TypeScript team hasn't accepted the linked issue #41303. If you can get it accepted, this PR will have a better chance of being reviewed. |
Seems the bot does not know about issue and pr... |
} | ||
|
||
class Derived extends Base { | ||
method = (x) => { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this should be supported, shouldn't it?
>Base : Base | ||
|
||
method(x, y, z) { } | ||
>method : (x: any, y: any, z: any) => void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need some parameter match here? Or just let them error.
>Derived : Derived | ||
>Base : Base | ||
|
||
method = (x) => { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this one should be support too?
tests/baselines/reference/contextualClassMethodParameter3.types
Outdated
Show resolved
Hide resolved
>Base : Base | ||
|
||
method(x = "a") { } | ||
>method : (x?: "a" | "b") => void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure too. "a" | "b" is a breaking changes for "string"
class Derived extends Base { | ||
method(x = "c") { } | ||
~~~~~~~ | ||
!!! error TS2322: Type '"c"' is not assignable to type '"a" | "b"'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems not correct.
class Derived extends Base { | ||
method(y = "a") { } | ||
~~~~~~~ | ||
!!! error TS7022: 'y' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not expected. But I have no idea about that...
Any updates on this? I find weird that typescript won't let me break the type but yet shows it as any. This is really worrying me about further uses. |
This PR needs some suggestions. |
This experiment is pretty old, so I'm going to close it to reduce the number of open PRs. |
Close #41303
Fixes #23911
Added some test cases.
Infer from interface does not support yet.