Skip to content
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

Conversation

Kingwl
Copy link
Contributor

@Kingwl Kingwl commented Feb 25, 2021

Close #41303
Fixes #23911

Added some test cases.

Infer from interface does not support yet.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Feb 25, 2021
@typescript-bot
Copy link
Collaborator

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.

@Kingwl
Copy link
Contributor Author

Kingwl commented Feb 25, 2021

Seems the bot does not know about issue and pr...

}

class Derived extends Base {
method = (x) => { }
Copy link
Contributor Author

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
Copy link
Contributor Author

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) => { }
Copy link
Contributor Author

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?

>Base : Base

method(x = "a") { }
>method : (x?: "a" | "b") => void
Copy link
Contributor Author

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"'.
Copy link
Contributor Author

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.
Copy link
Contributor Author

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...

@sandersn sandersn added the Experiment A fork with an experimental idea which might not make it into master label Mar 4, 2021
@darklight9811
Copy link

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.

@Kingwl
Copy link
Contributor Author

Kingwl commented Jun 8, 2021

This PR needs some suggestions.

@sandersn
Copy link
Member

This experiment is pretty old, so I'm going to close it to reduce the number of open PRs.

@sandersn sandersn closed this May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experiment A fork with an experimental idea which might not make it into master For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Experiment with always using parameters from base types for derived methods
5 participants