Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

# Suggestion: Range as Number type

See original GitHub issue

When defining a type one can specify multiple numbers separated by `|`.

``````type TTerminalColors = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
``````

Allow to specify number types as ranges, instead of listing each number:

``````type TTerminalColors = 0..15;
type TRgbColorComponent = 0..255;
type TUInt = 0..4294967295;
``````

Maybe use `..` for integers and `...` for floats.

``````interface Math {
random(): 0...1
}

type RandomDice = 1..6;

const roll: RandomDice = Math.floor(Math.random() * 6);
// Error: -------------------------^ Maybe use Math.ceil()?
``````

### Issue Analytics

• State:
• Created 6 years ago
• Reactions:1389

178reactions
panuhorsmalahticommented, Aug 18, 2017

This idea can be expanded to characters, e.g. `"b".."d"` would be `"b" | "c" | "d"`. It would be easier to specify character sets.

68reactions

@aluanhaddad actually it would be far from infinite in IEEE floating point. It would have 1,065,353,217 inhabitants by my calculations.

#### Top Results From Across the Web

typescript - Is it possible to restrict number to a certain range
For smallish ranges, this answer works: type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] ...
Typescript Numeric Range Type - DEV Community ‍ ‍
Typescript will complain if your starting number is 1000 or your range size is 1000.
<input type="range"> - HTML: HyperText Markup Language
<input> elements of type range let the user specify a numeric value which must be no less than a given value, and no...
HTML input type="range" - W3Schools
Default range is 0 to 100. However, you can set restrictions on what numbers are accepted with the attributes below. max - specifies...
How to Select the Right Data Types | Tutorial by Chartio
Data types define what kind and range of data can be stored in a given field (or column). ... The kind of data...

#### Troubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free