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
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.
The text was updated successfully, but these errors were encountered:
Llorx
changed the title
Apply inference in method interfaces when using a discriminator
Apply inference in method arguments when using a discriminator
Oct 29, 2024
🔎 Search Terms
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.⏯ Playground Link
https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAjgHgEoFEDKBGAPmQG8BYAKGSuRgFcQE8AKASgC5t8BuC6m+hACYA-GxAQAbtB6VqdBgGYmAEzhg4bAHIB7AJIgY0TLkLsJ24MpkBfCqEixEKAEbH8AGmSdBRMrKryjKwcJjJ8gYIqaho6+oZQbqYhOIJhcgJKqupaegZG3gRmFlYUtuRgAJ4ADigAtsAAHomeBcgAvKiJRAA+yK6ceC24PjIUgWDA2iA0zV7DBFHZ9U0DQymFJBSlY0x+4QLMLJv+fMhQEGC0UNN4ggq81NbuDwECkVlwR3unVOeX18gAES3BSAl7IJ7gwKZaJfZAAenhyAACnAoHBahdoMgAOQfHHIYC1KoAG2ACGAYBJFWQAAs4ABnVDTHFwEAVAmVGoAOi2JzK1hYXCAA
💻 Code
🙁 Actual behavior
It happens that
func3
argument is not properly inferred as is trying to infer thea
interface, although it doesn't apply because the requirement for that interface is to explicitly not have afunc2
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 offunc1
orfunc2
depending iffunc2
exists or not, like a transformer, but everything inside the same interface.The text was updated successfully, but these errors were encountered: