Skip to main content

prefer-ts-extras-is-integer

Prefer isInteger from ts-extras over Number.isInteger(...).

This keeps predicate usage consistent with other ts-extras narrowing helpers.

Targeted pattern scopeโ€‹

This rule focuses on direct Number.isInteger(value) calls that can be migrated to isInteger(value) with deterministic fixes.

  • Number.isInteger(value) call sites that can use isInteger(value).

Alias indirection, wrapper helpers, and non-canonical call shapes are excluded to keep isInteger(value) migrations safe.

What this rule reportsโ€‹

This rule reports Number.isInteger(value) call sites when isInteger(value) is the intended replacement.

  • Number.isInteger(value) call sites that can use isInteger(value).

Why this rule existsโ€‹

isInteger standardizes whole-number validation with the rest of the ts-extras numeric predicate family.

  • Numeric guard naming is consistent.
  • Native/helper predicate mixing is reduced.
  • Integer validation reads the same across services and packages.

โŒ Incorrectโ€‹

const isWhole = Number.isInteger(value);

โœ… Correctโ€‹

const isWhole = isInteger(value);

Behavior and migration notesโ€‹

  • Runtime behavior matches native Number.isInteger.
  • Decimal numbers still return false.
  • Numeric strings are not coerced to numbers.

Additional examplesโ€‹

โŒ Incorrect โ€” Additional exampleโ€‹

if (Number.isInteger(retryCount)) {
useRetries(retryCount);
}

โœ… Correct โ€” Additional exampleโ€‹

if (isInteger(retryCount)) {
useRetries(retryCount);
}

โœ… Correct โ€” Repository-wide usageโ€‹

const whole = isInteger(userInput);

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-ts-extras-is-integer": "error",
},
},
];

When not to use itโ€‹

Disable this rule if your codebase requires direct Number.isInteger usage.

Package documentationโ€‹

ts-extras package documentation:

Source file: source/is-integer.ts

/**
A strongly-typed version of `Number.isInteger()`.

@category Improved builtin
@category Type guard
*/

Rule catalog ID: R020

Further readingโ€‹

Adoption resourcesโ€‹