Skip to content

Hope const number types can do simple arithmetic operations #34844

Description

@samchon

When define a const Array type, its Array.length type also be the constant value. However, type of Array.length - 1 is not the constant value because TypeScript does not support minus operation between const number types.

Thus, I hope TypeScript to support the simple arithmetic operations on the const number types.

type SomeNumber = 3;
type SomeOperatedNumber = 3 - 1; // NOT POSSIBLE

function main(): void
{
    let someArray: [number, string, false] = [1, "something", false];
    let length: 3 = someArray.length;
    let lastIndex: number = someArray.length - 1; // not 2, but number
}

Activity

  1. RyanCavanaugh commented on Oct 31, 2019

    @RyanCavanaugh
    Member

    Duplicate #26382

  2. locked as resolved and limited conversation to collaborators on Oct 21, 2025
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

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions