Bug: Conditional types don't properly propagate this #28164
Labels
Domain: Conditional Types
The issue relates to conditional types
Working as Intended
The behavior described is the intended behavior; this is not a bug
TypeScript Version: 3.1.1-insiders.20180926
Search Terms: this conditional
Code
Expected behavior:
this
should be convertible toAddWith<this, whatever>
Actual behavior:
Motivation:
I'm building a builder class which builds configuration both in the type system and at runtime.
I don't want to repeat all of the existing type parameters (which have long names) in every method that adds a type to
TWith
Playground Link: http://www.typescriptlang.org/play/#src=class%20Builder%3CT1%2C%20T2%2C%20T3%2C%20TWith%3E%7B%0D%0A%20%20%20%20private%20_noStructuralTyping%3A%20undefined%3B%0D%0A%0D%0A%20%20%20%20withBroken%3CTAlsoWith%3E()%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20this%20as%20AddWith%3Cthis%2C%20TAlsoWith%3E%3B%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20withBroken2%3CTAlsoWith%3E()%3A%20AddWith%3Cthis%2C%20TAlsoWith%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20this%3B%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20withWorking%3CTAlsoWith%3E()%3A%20Builder%3CT1%2C%20T2%2C%20T3%2C%20TWith%7CTAlsoWith%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20this%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0A%0D%0Atype%20AddWith%3CTBuilder%2C%20TAlsoWith%3E%20%3D%20TBuilder%20extends%0D%0A%20%20%20%20Builder%3Cinfer%20T1%2C%20infer%20T2%2C%20infer%20T3%2C%20infer%20TWith%3E%3F%0D%0A%20%20%20%20Builder%3CT1%2C%20T2%2C%20T3%2C%20TWith%7CTAlsoWith%3E%3A%0D%0A%20%20%20%20never%3B%0D%0A%0D%0Aconst%20test%20%3D%20new%20Builder%3C1%2C%202%2C%203%2C%20string%3E().withBroken%3Cnumber%3E()%3B%0D%0A%0D%0A%2F%2F%20Without%20using%20the%20%60this%60%20type%2C%20it%20works%20as%20expected%3A%0D%0Aconst%20simpleTest%20%3D%20new%20Builder%3C1%2C%202%2C%203%2C%20string%3E()%3B%0D%0Atype%20WithNumber%20%3D%20AddWith%3Ctypeof%20simpleTest%2C%20number%3E%3B%0D%0Aconst%20demo%3A%20WithNumber%20%3D%20simpleTest%3B
Related Issues: #28159
The text was updated successfully, but these errors were encountered: