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

Hope const number types can do simple arithmetic operations #34844

Closed
samchon opened this issue Oct 31, 2019 · 1 comment
Closed

Hope const number types can do simple arithmetic operations #34844

samchon opened this issue Oct 31, 2019 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@samchon
Copy link

samchon commented Oct 31, 2019

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
}
@RyanCavanaugh
Copy link
Member

Duplicate #26382

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants