-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Type parameter inference of function chained parameters and return values does not work. #38872
Comments
Similar issue with a single function consuming its own return type:
|
Facing the same issue. I also found a possibly related issue: #38845 |
@ahejlsberg design limitation or did I miss something? |
This is a design limitation. In the original example, the expressions provided for the In order to support this particular scenario we'd need additional inference phases, i.e. one per contextually sensitive property value, similar to what we do for multiple contextually sensitive parameters. Not clear that we want to venture there, and it would still be sensitive to the order in which object literal members are written. Ultimately there are limits to what we can do without full unification in type inference. |
I'm writing an API with life cycle methods that are called in a specific order. Each life cycle method can return a 'state' object that is passed to the next life cycle method. I would like the API to be strongly typed, and the type of the state parameters to be inferenced from the return type of the previous life cycle method.
TypeScript Version: 3.9.2, 4.0.0-dev.20200530
Search Terms:
chain inference inference parameter
Code
Expected behavior:
No error.
Actual behavior:
Error 2322 on
const x: string = b
Removing the
a
parameter removes the error and works as expected, e.g.Explicitly providing the parameter type also works, e.g.
Playground Link:
https://www.typescriptlang.org/play?#code/C4TwDgpgBAwgFgQwJYDsA8AlAjAGihgJgD4oBeKAbwCgooEAKASgC59caoAjehV7F-AQDcHAMb1OfAgIBuAeyQATEQF8qVAGYBXFKOBI5KKMAgBnYJlyCi9DXLmt4ydNjyEijSurVUT5+tS0vFBMZCQADDgckiEInqQkAOQIiVG0oqwS8SSBtFCihuZQAB6s5gBOqADmZFwitGoqjCJAA
Related Issues:
The text was updated successfully, but these errors were encountered: