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
Playing around with the type definitions for React 0.13 I ran into this problem:
declare module Test{interfaceParent{y: number;}interfaceChildextendsParent{z: string;}interfaceParentDeriv{yderiv: number;}interfaceChildDerivextendsParentDeriv{zderiv: string;}interfaceApi{makeParent(): Parent;makeChild(): Child;meth(element: Parent): ParentDeriv;meth(element: Child): ChildDeriv;}varapi: Api;}varx=Test.api.meth(Test.api.makeParent());x.zderiv;// Should be: error. Is: error.vary=Test.api.meth(Test.api.makeChild());// takes wrong method.y.zderiv;// Should be: ok. Is: error. y is inferred ParentDeriv.
But if you flip the method declarations around, it works fine:
declare module Test{interfaceParent{y: number;}interfaceChildextendsParent{z: string;}interfaceParentDeriv{yderiv: number;}interfaceChildDerivextendsParentDeriv{zderiv: string;}interfaceApi{makeParent(): Parent;makeChild(): Child;// Note order: child class firstmeth(element: Child): ChildDeriv;meth(element: Parent): ParentDeriv;}varapi: Api;}varx=Test.api.meth(Test.api.makeParent());x.zderiv;// Should be: error. Is: error.vary=Test.api.meth(Test.api.makeChild());y.zderiv;// Should be: ok. Is: ok.
This is a bug, right? With TS I'm never sure..
Tested with 1.4 (Playground and local)
The text was updated successfully, but these errors were encountered:
Overload ordering absolutely matters. The rule is that the first applicable overload is chosen. We tried a bunch of other rules and this was the only one anyone could ever make sense of in practice.
This does mean that it's possible to write overloads which are "unreachable" by putting the general signature before the more specific overload; care needs to be taken to put the more-specific overloads first.
Playing around with the type definitions for React 0.13 I ran into this problem:
But if you flip the method declarations around, it works fine:
This is a bug, right? With TS I'm never sure..
Tested with 1.4 (Playground and local)
The text was updated successfully, but these errors were encountered: