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
interfaceFactory<T>{(): T;mixin<U>(mixin: U): T&U;}functioncompose<T>(base: T): Factory<T>{return;}constfactory=compose({foo(){returnthis;},bar(){this.foo();// <-- properly contextual and literal union typereturn()=>{returnthis;// <-- type `any`, but should be same as outside the lambda};}});constfoobar={foo(){returnthis;},bar(){return()=>{returnthis;// <-- correct object literal type};}};
Outside of the lambda function in the first object literal, this is an intersection type of the object literal and the contextual type (which happen to be the same). In the second example, this is properly the object literal type including within the scope of the lambda function.
The text was updated successfully, but these errors were encountered:
DanielRosenwasser
changed the title
Object literal contextual typing this widening to any in lambda functions
Object literal contextual typing where 'this' has type 'any' in lambda functions
Apr 29, 2016
#8389 is in -- it fixes this bug by making both references to this be of type any. Which is technically the same type, but not a useful one. We decided that we couldn't do the right thing for the majority of uses of this in object literals, like those in this bug and #8191.
TypeScript Version:
nightly (1.9.0-dev.20160429)
Code
Expected behavior:
That both references to
this
are typed the same.Actual behavior:
I am pretty sure this is related to #8356.
Outside of the lambda function in the first object literal,
this
is an intersection type of the object literal and the contextual type (which happen to be the same). In the second example,this
is properly the object literal type including within the scope of the lambda function.The text was updated successfully, but these errors were encountered: