Skip to content

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

License

Notifications You must be signed in to change notification settings

kaufco/number-types

Repository files navigation

@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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published