Skip to content

[Feature Request] Support for Digit and Digits #39

Open

Description

@brandonmcconnell

It would be helpful to be able to specify Digits and Digit types.

Definitions

import * as H from 'hotscript'

type Digits<T extends number> = H.Eval<H.Unions.Range<
  H.Eval<H.N.Power<10, H.Eval<H.N.Sub<T, 1>>>>,
  H.Eval<H.N.Sub<H.Eval<H.N.Power<10, T>>, 1>>
>> | (T extends 1 ? 0 : never);

type Digit = Digits<1>;

Usages

const some1DigitNumber: Digit = 5; // ✅
const some1DigitNumberString: `${Digit}` = "5"; // ✅
const some2DigitNumber: Digits<2> = 99; // ✅
const some2DigitNumberString: `${Digits<2>}` = "99"; // ✅

TypeScript Playground: https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wBJwGZQiOAcgAsIZUBjKYMGQg…


UPDATE: I've refined the example to include the recently supported Unions.Range.

Activity

  1. changed the title [-]Support for `Digit` and `Digits`[/-] [+][Feature Request] Support for `Digit` and `Digits`[/+] on Feb 17, 2023
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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions