microsoft/TypeScript

numeric literal types disrespect arithmetics

zpdDG4gta8XKpMCd opened this issue · 5 comments

declare var a : -1 | 0 | 1;
a = -a; // <-- problem

It was one of the design decisions not do do any type arithmetic. see #8112.

Hm. Is that what #8112 meant by this?

Currently has some strange behavior for flow of arithmetic on types.

I hadn't managed to find mention of this in #7480 either. Were there any specific issues there we could think along on?

mstn commented

@mhegazy, out of curiosity, which problems did you find for flow of arithmetic on types? As @tycho01 pointed out, there is no reference to this in the issue you mentioned.

jcalz commented

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