number uint16 - nberlette/is GitHub Wiki
function isUint16<N = number>(it: N): it is Uint16<N>;
Checks if a given value is an unsigned 16-bit integer.
Name | Info |
---|---|
it |
The value to check. |
true
if it
is an unsigned 16-bit integer, false
otherwise.
Numbers
number
unsigned
integer
import { isUint16, type MaybeUint16, type Uint16 } from "@nick/is/number";
let value = 1 as Uint16;
const setValue = (newValue: MaybeUint16) => {
if (isUint16(newValue)) value = newValue;
};
setValue(0xFFFF); // <- No error!
// This will raise a TypeScript compiler error:
value = -1; // <- TS2322 Type '-1' is not assignable to type 'Uint16'.
function isUint16(it: unknown): it is Uint16<number>;
Checks if a given value is an unsigned 16-bit integer.
Name | Info |
---|---|
it |
The value to check. |
true
if it
is an unsigned 16-bit integer, false
otherwise.
Numbers
number
unsigned
integer
import { isUint16, type MaybeUint16, type Uint16 } from "@nick/is/number";
let value = 1 as Uint16;
const setValue = (newValue: MaybeUint16) => {
if (isUint16(newValue)) value = newValue;
};
setValue(0xFFFF); // <- No error!
// This will raise a TypeScript compiler error:
value = -1; // <- TS2322 Type '-1' is not assignable to type 'Uint16'.
export type MaybeUint16<N = number> = Cast<N, MAYBE_UINT16>;
Casts a value into a partial unsigned 16-bit integer type.
-
N
(default:number
)
Numbers
Types
maybe
unsigned
integer
import { isUint16, type MaybeUint16, type Uint16 } from "@nick/is/number";
let value = 1 as Uint16;
const setValue = (newValue: MaybeUint16) => {
if (isUint16(newValue)) value = newValue;
};
setValue(0xFFFF); // <- No error!
// This will raise a TypeScript compiler error:
value = -1; // <- TS2322 Type '-1' is not assignable to type 'Uint16'.
export type Uint16<N = number> = Cast<N, UINT16>;
Casts a value into an unsigned 16-bit integer type.
-
N
(default:number
)
Numbers
Types
unsigned
integer
import { isUint16, type MaybeUint16, type Uint16 } from "@nick/is/number";
let value = 1 as Uint16;
const setValue = (newValue: MaybeUint16) => {
if (isUint16(newValue)) value = newValue;
};
setValue(0xFFFF); // <- No error!
// This will raise a TypeScript compiler error:
value = -1; // <- TS2322 Type '-1' is not assignable to type 'Uint16'.