Skip to content

numeric literal types disrespect arithmetics #15645

Open

Description

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

Activity

  1. mhegazy commented on May 8, 2017

    @mhegazy
    Contributor

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

  2. KiaraGrouwstra commented on May 18, 2017

    @KiaraGrouwstra
    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?

  3. mstn commented on Apr 23, 2018

    @mstn

    Mohamed Hegazy (@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.

  4. jcalz commented on Aug 12, 2018

    @jcalz
    Contributor

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

  5. unional commented on Oct 9, 2020

    @unional
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions