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
// signaturefunctionfoo(xx: number): number;functionfoo(xx: number,yy: string): string;// implementation// βοΈit may return `boolean`, differing to the signaturesfunctionfoo(xx: number,yy?: string): number|string|boolean{if(yy==null){returnxx;}if(yy==="666"){returntrue;}returnyy;}
π Actual behavior
Obviously, the implementation doesn't satisfy the signatures, but TS didn't "find" it. It confused me, and brought some issues into my project.
I don't know whether it is by-design or a bug, and I didn't find any doc about this behavior. Please tell me the reason of this design, if it is by-design.
π Expected behavior
// signature// EXPECTED: Tell me "This overload signature is not compatible with its implementation signature."functionfoo(xx: number): number;functionfoo(xx: number,yy: string): string;// implementationfunctionfoo(xx: number,yy?: string): number|string|boolean{// ...}
The text was updated successfully, but these errors were encountered:
Overload checking is necessarily loose because it's pretty much impossible to constrain it in a way that makes it fully sound without overcomplicating the rules and getting in the way. For example, the same kind of unsoundness happens even with the "correct" signature:
...namely that nothing prevents you from returning the wrong type for the overload that was actually called. There doesn't really seem to be an easily generalizable mechanism by which you could reject the case in the OP without also rejecting the "correct" signature, either, since both cases involve a return type which is simultaneously wider than both overloads'. So what would the rule for that be?
Bug Report
π Search Terms
overload, implementation, signature, different, compatible
π Version & Regression Information
β― Playground Link
code in playground
π» Code
π Actual behavior
Obviously, the implementation doesn't satisfy the signatures, but TS didn't "find" it. It confused me, and brought some issues into my project.
I don't know whether it is by-design or a bug, and I didn't find any doc about this behavior. Please tell me the reason of this design, if it is by-design.
π Expected behavior
The text was updated successfully, but these errors were encountered: