# ts-number-range

> This package provides two type aliases which allow you to create number ranges easier.

Latest version **1.0.4** (published 2021-11-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-number-range
pnpm add ts-number-range
yarn add ts-number-range
bun add ts-number-range
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2021-11-16 |
| First published | 2021-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Florian Völker |
| Maintainers | feirell |
| Keywords | typescript, typings, range |

## Links

- npm: https://www.npmjs.com/package/ts-number-range
- Repository: https://github.com/feirell/ts-number-range
- Homepage: https://github.com/feirell/ts-number-range#readme
- Issues: https://github.com/feirell/ts-number-range/issues
- npm.io page: https://npm.io/package/ts-number-range

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2021-11-16
- 1.0.3 — 2021-11-16
- 1.0.2 — 2021-03-19
- 1.0.1 — 2021-03-19
- 1.0.0 — 2021-03-19

## README

# ts-number-range

This package provides two type aliases which allow you to create number ranges easier.

## limitiations

**Be aware that this is not a real solution, but a workaround which only works in a very limited range in respect to the bounds
of the range. 41 is the current maximum recursion depth, so the max range is 0 | 1 | ... | 40.** 

## Types

```typescript
import { NumbersToN, NrRange } from "ts-number-range";

// type is equivalent to `0 | 1 | 2 | 3 | 4`
let a: NumbersToN<5>;

// type is equivalent to `4 | 5 | 6 | 7`
let b: NrRange<4, 8>
```

## TypeScript 4.5 Tail-Recursion elimination

With TypeScript 4.5-beta a type tail-recursion elimination was introduced.
Luckily the provided typings are in the correct form which enables this feature and allows a much greater range.

A quick test resulted in a range from 0 | ... | 997:

![Example error message](readme-media/with-tail-rec.png?raw=true "With tail recursion elimination")

So now ranges work for a greater offset too:

![Example error for a range](readme-media/number-range.png?raw=true "Range with great offset")

---
_Source: https://npm.io/package/ts-number-range · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
