-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Incorrectly inferred return type of method of a generic class #60406
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
Comments
Seems like #33181. Indexed accesses into generic objects with non-generic keys tend to widen those generics to their constraints first. So if you have |
This is a very simple example and it is easy to set type but lets add some additional code.
|
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
🔎 Search Terms
function return type incorrectly inferred from type argument
🕗 Version & Regression Information
Looks like this is the behavior in every version I tried and I can't find information about inferring types for the non-generic methods in generic classes.
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.6.3#code/JYOwLgpgTgZghgYwgAgJIhgewDwBVkQAekIAJgM7LlhSgDmyAPlTfQNoC6AfMgN4CwAKGQjkANzgAbYKThhMUAFzIAFAEpkAXh64A3EIC+QoQklxylAMIBGPAWIQyldFmzVaIBs3ftuPAcKioFgA-Mp6QqLiUjJyCtbqfJFRolAQYACuUCDIYAAWwOQAdMGYIUUS0rLyUPqBIkb10VVxUABM6uFsAOSVsTXdHEzIGWQQMKAQpElNUWmZ2bkFxaXlfdUKdVGNjSaYINTICFrIIBAA7sg22C44Pp5cXOp1CPuHwGInCCUYZRUxG1qyAA9MDcgBPAAOKEKqkS2hYHjoGmYo1I40mpD2BzA4msX3+LRqCTUuhBYLAUJhlBU8J49y8iN8KJGYwmZyxgleOPEbQJ61aHVJ5Ih0OQsNpGgRDJZaIxHKEQA
💻 Code
🙁 Actual behavior
Return type of
validator
method for classC1<Info<string>>
is(() => string | string[]) | undefined
🙂 Expected behavior
Return type of
validator
method for classC1<Info<string>>
should be(() => string) | undefined
Additional information about the issue
Looks like the return type for generic class methods is only inferred via the type argument constraint and does not change in a particular instance of the class.
The text was updated successfully, but these errors were encountered: