question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

numeric literal types disrespect arithmetics

See original GitHub issue
declare var a : -1 | 0 | 1;
a = -a; // <-- problem

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:13
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jcalzcommented, Aug 12, 2018

#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)

0reactions
unionalcommented, Oct 9, 2020

There are Inc<> and Dec<> (typical) and Minus<> (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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found