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
Argument of type 'AB' is not assignable to parameter of type '"A"'.
It works correctly if I just use value: 'A' | 'B' as the argument to bounceAndTakeIfA, but since I want the return value to type-match the input, I need to use the generic (overloading could do it, but overloading is brittle and error-prone, since there is no error-checking that the overload signatures are actually correct; my team has banned them for that reason). But (I'm guessing) since AB extends 'A' | 'B', narrowing doesn't happen. In reality, I am just using extends to mean AB ⊂ 'A' | 'B', but extendscan mean more than that, which (I suspect) is why TS is refusing to narrow on it.
Some alternative to extends that more specifically means ⊂ (subsets maybe?) would probably be the best solution here?
TypeScript Version: 2.2.0-dev.20170126
Code
Expected behavior:
Compiles without error.
Actual behavior:
It works correctly if I just use
value: 'A' | 'B'as the argument tobounceAndTakeIfA, but since I want the return value to type-match the input, I need to use the generic (overloading could do it, but overloading is brittle and error-prone, since there is no error-checking that the overload signatures are actually correct; my team has banned them for that reason). But (I'm guessing) sinceAB extends 'A' | 'B', narrowing doesn't happen. In reality, I am just usingextendsto meanAB ⊂ 'A' | 'B', butextendscan mean more than that, which (I suspect) is why TS is refusing to narrow on it.Some alternative to
extendsthat more specifically means ⊂ (subsetsmaybe?) would probably be the best solution here?