prefer-ts-extras-is-safe-integer
Prefer isSafeInteger from ts-extras over Number.isSafeInteger(...).
This keeps predicate usage consistent with other ts-extras narrowing helpers.
Targeted pattern scopeโ
This rule focuses on direct Number.isSafeInteger(value) calls that can be migrated to isSafeInteger(value) with deterministic fixes.
Number.isSafeInteger(value)call sites that can useisSafeInteger(value).
Alias indirection, wrapper helpers, and non-canonical call shapes are excluded to keep isSafeInteger(value) migrations safe.
What this rule reportsโ
This rule reports Number.isSafeInteger(value) call sites when isSafeInteger(value) is the intended replacement.
Number.isSafeInteger(value)call sites that can useisSafeInteger(value).
Why this rule existsโ
isSafeInteger standardizes safe-integer validation and keeps numeric guard usage consistent with other ts-extras helpers.
- Safety-bound checks use one helper convention.
- Predicate style is consistent with
isIntegerandisFinite. - Guard code for IDs/counters avoids mixed native/helper forms.
โ Incorrectโ
const isSafe = Number.isSafeInteger(value);
โ Correctโ
const isSafe = isSafeInteger(value);
Behavior and migration notesโ
- Runtime behavior matches native
Number.isSafeInteger. - Values outside
Number.MIN_SAFE_INTEGER/Number.MAX_SAFE_INTEGERreturnfalse. - Non-number values are not coerced.
Additional examplesโ
โ Incorrect โ Additional exampleโ
if (Number.isSafeInteger(quantity)) {
persist(quantity);
}
โ Correct โ Additional exampleโ
if (isSafeInteger(quantity)) {
persist(quantity);
}
โ Correct โ Repository-wide usageโ
const supported = isSafeInteger(index);
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-ts-extras-is-safe-integer": "error",
},
},
];
When not to use itโ
Disable this rule if your team enforces native Number.isSafeInteger calls.
Package documentationโ
ts-extras package documentation:
Source file: source/is-safe-integer.ts
/**
A strongly-typed version of `Number.isSafeInteger()`.
@category Improved builtin
@category Type guard
*/
Rule catalog ID: R023