@kobayami/number-types

A minor package that provides type aliases int, long, float and double in TypeScript

Usage no npm install needed!

<script type="module">
  import kobayamiNumberTypes from 'https://cdn.skypack.dev/@kobayami/number-types';
</script>

README

@kobayami/number-types

Installation

npm install --save @kobayami/number-types

Version and License

Summary

A minor package that provides the type aliases int, long, float and double for number types in TypeScript. The types int, float and double are aliases for number, long is an alias for bigInt.

While the TypeScript compiler cannot enforce the associated number ranges (e.g., restricting int to the 32 bit signed integer range), these type aliases allow for a more precise notation of number types. This serves documentation purposes and makes the code more readable. For example, a variable that represents an index could be declared an int, while a variable used for computations could be declared a double.

Also, this may simplify things if code should later be ported from TypeScript to some other language.

Usage Example

import { int, double } from "@kobayami/number-types";

function getElementAt<T>(array: T[], index: int): T {
    return array[index];
}

function getDistance(velocity: double, time: double): double {
    return velocity * time;
}

See Also