-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Argument type infer not work correctly without specify types of function params #47577
Comments
Feels like #38872 |
@jcalz So in this situation is there any better soluation to make it work? |
Split the single object into multiple parameters like this? (Note that the specific type named |
@jcalz THX very much, help a lot. Is there any article about context sensitive of typescript? I still not quite understand why the demo you provide solve this issue. I looked at the linked issue (also some issue related by it), I assume |
A context sensitive function is not fully annotated and so the compiler must use contextual typing to infer something about its type. According to this comment the compiler performs a phase of inference for every function parameter which is context sensitive, but it does not perform multiple phases of inference for a single function parameter. |
I opened #47599 to track further work in the area |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
@jcalz Your answer is very helpful, but I still don't understand how splitting into multiple parameters works. In your example, if I switch the position of 'commits' and 'actions', the type derivation still does not work properly |
Some inference only works from left-to-right in order of parameters, see this comment for example. |
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
seems to be every version of typescript shows this behavior
⏯ Playground Link
Playground Link
In this example, if you try the use
commits
inactions.a
, you will see the type ofcommits
is:If I update the commit function to use
state: State
,then the
commits
type inactions.a
will be exactly whatcommits
is, eg:🙁 Actual behavior
Without specify
state: State
, the commits type infer inactions.a
not correct. I suppose TS will infer what state is, and there should not be different with/without specifystate: State
.🙂 Expected behavior
there should not be different with/without specify
state: State
.The text was updated successfully, but these errors were encountered: