Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numeric literal types disrespect arithmetics #15645

Open
zpdDG4gta8XKpMCd opened this issue May 7, 2017 · 5 comments
Open

numeric literal types disrespect arithmetics #15645

zpdDG4gta8XKpMCd opened this issue May 7, 2017 · 5 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@zpdDG4gta8XKpMCd
Copy link

declare var a : -1 | 0 | 1;
a = -a; // <-- problem
@mhegazy
Copy link
Contributor

mhegazy commented May 8, 2017

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

@mhegazy mhegazy added the Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature label May 8, 2017
@KiaraGrouwstra
Copy link
Contributor

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
Copy link

mstn commented Apr 23, 2018

@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
Copy link
Contributor

jcalz commented 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)

@unional
Copy link
Contributor

unional commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

7 participants
@jcalz @mstn @zpdDG4gta8XKpMCd @KiaraGrouwstra @unional @mhegazy and others