-
-
Notifications
You must be signed in to change notification settings - Fork 0
number negative
Nicholas Berlette edited this page Jun 19, 2025
·
1 revision
function isNegative<N = number>(it: N): it is Negative<N>;Checks if a given value is a negative number.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value is a negative number, false otherwise.
Numbers
negative
import { isNegative } from "jsr:@nick/is/integer";
console.log(isNegative(0)); // false
console.log(isNegative(1)); // false
console.log(isNegative(1.5)); // false
console.log(isNegative(NaN)); // false
console.log(isNegative(Infinity)); // false
console.log(isNegative(-0)); // true
console.log(isNegative(-1)); // true
console.log(isNegative(-Infinity)); // truefunction isNegative(it: unknown): it is Negative<number>;Checks if a given value is a negative number.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value is a negative number, false otherwise.
Numbers
negative
import { isNegative } from "jsr:@nick/is/integer";
console.log(isNegative(0)); // false
console.log(isNegative(1)); // false
console.log(isNegative(1.5)); // false
console.log(isNegative(NaN)); // false
console.log(isNegative(Infinity)); // false
console.log(isNegative(-0)); // true
console.log(isNegative(-1)); // true
console.log(isNegative(-Infinity)); // trueexport type MaybeNegative<N = number> = Cast<N, MAYBE_NEGATIVE>;Casts a value into a partial negative type. If the value is not a number, it
will resolve to never.
-
N(default:number)
Types Numbers
maybe negative number
import { isNegative, type MaybeNegative } from "jsr:@type/number";
let x = -1 as MaybeNegative, y = 0;
if (isNegative(x)) {
console.log(x);
} else {
console.log(y);
}
y = -1; // <- No error! (this is the main difference from `Negative`)export type Negative<N = number> = Cast<N, NEGATIVE>;Casts a value into a negative type. If the value is not a number, it will
resolve to never.
-
N(default:number)
Numbers Types
negative number
import { isNegative, type Negative } from "jsr:@type/number";
let x = -1 as Negative, y = 0;
if (isNegative(x)) {
console.log(x);
} else {
console.log(y);
}
// This will raise a TypeScript compiler error:
x = 0; // <- TS2322 Type '0' is not assignable to type 'Negative'.