Applying a known operator to a union type should be inferred as the corresponding union type #40608
Closed
5 tasks done
Labels
Duplicate
An existing issue was already created
Search Terms
union type, operators, inference, numbers, math, calculation, addition, multiplication
Suggestion
Given a union type of numbers, or strings (for example
-1 | 1
), when we apply a known operator on it (for example2 * x
) it currently result in typenumber
. Though it is possible to make this type stronger by inferring the type-2 | 2
from it.Examples
We can do this with strings too:
Use Cases
For example writing a comparator function:
Another example,
Let's say I'm using a string to code some sort of information.
Checklist
My suggestion meets these guidelines:
Anything that was considered number before, will be considered a more specific case of number, thus still assignable to number.
The text was updated successfully, but these errors were encountered: