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
You expect the TypeScript compiler to implement the absorption laws, but it doesn't. There's also a wrinkle here that intersection of function types are interpreted as overloads, so that could possibly complicate how absorption would work with function types. 🤷♂️
Like @jcalz said, (A | B) & A is actually A | (A & B), and intersections of object types don't obliterate each other to never - they're purely additive.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.7.0-dev.201xxxxx
Code
Expected behavior:
Compiles, because the (A|B) & A == A
Actual behavior:
Assignment to 'value' fails with:
Type 'string | number' is not assignable to type 'number'.
Background
Aside being a correctness issue, the motivation here is to enable type guards which narrow the return type of a function:
The text was updated successfully, but these errors were encountered: