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
classBuilder{private_class: undefined;withFoo<T>(){returnthisas this &{foo: T}}withBar<T>(){returnthisas this &{bar: T}}withFooBar<T>(){returnthis.withFoo<T>().withBar<T>();}}letgood=newBuilder().withFoo<number>().withBar<number>();letbad=newBuilder().withFooBar<number>();good=bad;
Looking at the quick info for withFooBar, it would appear that we instantiate the this type for the withBar call in the method body with the class's this, rather than the call target (which would be this & {foo:T}).
TypeScript Version: 3.1.1-insiders.20180926
Search Terms: this chain
Code
Expected behavior:
good
&bad
should be identicalActual behavior:
bad
is missingfoo
Playground Link: http://www.typescriptlang.org/play/#src=class%20Builder%20%7B%0D%0A%20%20%20%20private%20_class%3A%20undefined%3B%0D%0A%20%20%20%20withFoo%3CT%3E()%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20this%20as%20this%20%26%20%7B%20foo%3A%20T%20%7D%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20withBar%3CT%3E()%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20this%20as%20this%20%26%20%7B%20bar%3A%20T%20%7D%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20withFooBar%3CT%3E()%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20this.withFoo%3CT%3E().withBar%3CT%3E()%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Alet%20good%20%3D%20new%20Builder().withFoo%3Cnumber%3E().withBar%3Cnumber%3E()%3B%0D%0Alet%20bad%20%3D%20new%20Builder().withFooBar%3Cnumber%3E()%3B%0D%0Agood%20%3D%20bad%3B
The text was updated successfully, but these errors were encountered: