-
-
Notifications
You must be signed in to change notification settings - Fork 667
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
feat: Constructor generic type inference #2894
base: main
Are you sure you want to change the base?
feat: Constructor generic type inference #2894
Conversation
Note - I didn't change any of the actual existing logic for type inference that was used for functions. I just extracted it for re-use by constructor "new expressions". The PR is best reviewed with the "hide whitespace" box checked. |
@mattjohnsonpint Thanks, that diff looks so much more manageable to review now. |
Note: it doesn't handle this case: class Foo<T> {
constructor(public x: T) {}
}
class Bar<T> extends Foo<T> {}
const x = new Bar("hi") That can probably be figured out at a later date. |
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 looks good, probably.
I might be able to address that. I'll take a look tomorrow. Good catch! |
It should handle that case now. Thanks! |
Also, FWIW, I don't think either of the previously existing test cases marked |
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 seems good.
I don't know what those are for either. I'm guessing it's something related to omitting |
Fixes #2893.
Changes proposed in this pull request:
Enables type inference for constructors of generic classes by:
Refactoring to extract the existing type inference logic for functions that was in
maybeInferCall
, into its own private methodinferGenericTypeArguments
.Calling that new method from
resolveClassInclTypeArguments
when a generic class's constructor is called without any type arguments.Expanding the unit tests to verify working functionality and no regressions.
I've read the contributing guidelines
I've added my name and email to the NOTICE file