You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Apply inference in method arguments when using a discriminator #60366
github: interface infer
github: interface discriminator
github: interface discriminator method
google: typescript method gets the result of another optional method
google: typescript one property sets the type of another property
google: typescript one property sets the type of the next property
🕗 Version & Regression Information
Happens from 3.3.3 (Removing NoInfer) up to the nightly version.
interfacea<RES1>{func1():RES1;func2?:never;func3(data:NoInfer<RES1>):void;}interfaceb<RES1,RES2>{func1():RES1;func2(data:NoInfer<RES1>):RES2;func3(data:NoInfer<RES2>):void;}typemix<RES1,RES2>=a<RES1>|b<RES1,RES2>;functionf<RES1,RES2>(data:mix<RES1,RES2>){}f({func1(){return123},func2(data){return"123"},func3(data){// Parameter 'data' implicitly has an 'any' type.}});
🙁 Actual behavior
It happens that func3 argument is not properly inferred as is trying to infer the a interface, although it doesn't apply because the requirement for that interface is to explicitly not have a func2 property.
If I change both func3 arguments to the same type (RES1 for example) it works, so it is actually getting both interfaces.
🙂 Expected behavior
I guess that it should first get the applicable interfaces, and then try to infer the values depending on the applicable interfaces only.
Additional information about the issue
Still, I'm not sure about this approach. What I want is to have a func3 method that receives the result of func1 or func2 depending if func2 exists or not, like a transformer, but everything inside the same interface.
changed the title [-]Apply inference in method interfaces when using a discriminator[/-][+]Apply inference in method arguments when using a discriminator[/+]on Oct 29, 2024
Activity
[-]Apply inference in method interfaces when using a discriminator[/-][+]Apply inference in method arguments when using a discriminator[/+]jcalz commentedon Oct 29, 2024
Kind of looks like another one for the #47599 pile.
RyanCavanaugh commentedon Nov 1, 2024
Yeah, this would require an unbounded number of passes (or maybe one pass per type argument, but it's unclear which order you'd use)
typescript-bot commentedon Nov 4, 2024
This issue has been marked as "Design Limitation" and has seen no recent activity. It has been automatically closed for house-keeping purposes.