1.0.0 • Published 4 years ago
@kobayami/number-types v1.0.0
@kobayami/number-types
Installation
npm install --save @kobayami/number-typesVersion 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
1.0.0
4 years ago