numeric literal types disrespect arithmetics
See original GitHub issuedeclare var a : -1 | 0 | 1;
a = -a; // <-- problem
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Implementing Arithmetic Within TypeScript's Type System |
Our goal is to have some type like Add that can take two numeric literal types and determine their sum. So we would...
Read more >Numeric Literals - IBM
A numeric literal is a character-string whose characters are selected from the digits 0 through 9, a sign character (+ or -), and...
Read more >PEP 515 – Underscores in Numeric Literals
The current proposal is to allow one underscore between digits, and after base specifiers in numeric literals. The underscores have no semantic meaning,...
Read more >C2124 is most disrespectful of IEEE floating point arithmetic
appropriate for integer arithmetic (as it'll generate a runtime SEH ... that the number of applications where dividing by a literal zero is...
Read more >Using Literals - sumations.net
Two kinds of numeric literals can be used in arithmetic expressions: integer and real. An integer literal is an optionally signed whole number...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
#26382 has been determined to be a duplicate of this, although that one is about allowing arithmetic at the type level at all, while this one seems to be more concerned with inference and flow.
Anyway, I think that now that tuple types are becoming more powerful it might be reasonable to revisit this idea so that we can get closer to the sort of dependent types needed for strongly typing such methods as
Function['bind']
. (Related to #26223)There are
Inc<>
andDec<>
(typical
) andMinus<>
(ts-toolbelt
).It is critical in doing type manipulation. The custom implementation has limitation and not efficient at all.
With
intrinsic
in TypeScript 4.1, it would be great if TypeScript can provide those base types.