prefer-ts-extras-array-find-last
Prefer arrayFindLast from ts-extras over array.findLast(...).
arrayFindLast(...) improves predicate inference and value narrowing in typed arrays.
Targeted pattern scopeโ
This rule focuses on direct array.findLast(predicate) calls that can be migrated to arrayFindLast(array, predicate) with deterministic fixes.
array.findLast(predicate)call sites that can usearrayFindLast(array, predicate).
Alias indirection, wrapper helpers, and non-canonical call shapes are excluded to keep arrayFindLast(array, predicate) migrations safe.
What this rule reportsโ
This rule reports array.findLast(predicate) call sites when arrayFindLast(array, predicate) is the intended replacement.
array.findLast(predicate)call sites that can usearrayFindLast(array, predicate).
Why this rule existsโ
arrayFindLast makes reverse-direction predicate lookups explicit and keeps them aligned with the ts-extras helper style.
- Reverse scans are easier to spot during code review.
- Call signatures stay consistent with
arrayFind/arrayFindLastIndex. - Utility code that depends on "latest match" is easier to audit.
โ Incorrectโ
const monitor = monitors.findLast((entry) => entry.id === targetId);
โ Correctโ
const monitor = arrayFindLast(monitors, (entry) => entry.id === targetId);
Behavior and migration notesโ
- Runtime behavior matches native
Array.prototype.findLast. - Search direction remains right-to-left.
- Result is the matching element, or
undefinedif no match exists.
Additional examplesโ
โ Incorrect โ Additional exampleโ
const latest = events.findLast((entry) => entry.type === "login");
โ Correct โ Additional exampleโ
const latest = arrayFindLast(events, (entry) => entry.type === "login");
โ Correct โ Repository-wide usageโ
const trailingError = arrayFindLast(logs, (entry) => entry.level === "error");
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-ts-extras-array-find-last": "error",
},
},
];
When not to use itโ
Disable this rule if your team intentionally uses native .findLast() everywhere.
Package documentationโ
ts-extras package documentation:
ts-extras@0.17.x does not currently expose arrayFindLast in its published API, so there is no canonical source/*.ts link for this helper yet.
Reference links:
Rule catalog ID: R004