prefer-ts-extras-array-find
Prefer arrayFind from ts-extras over array.find(...).
arrayFind(...) improves predicate inference and value narrowing in typed arrays.
Targeted pattern scopeโ
This rule focuses on direct array.find(predicate) calls that can be migrated to arrayFind(array, predicate) with deterministic fixes.
array.find(predicate)call sites that can usearrayFind(array, predicate).
Alias indirection, wrapper helpers, and non-canonical call shapes are excluded to keep arrayFind(array, predicate) migrations safe.
What this rule reportsโ
This rule reports array.find(predicate) call sites when arrayFind(array, predicate) is the intended replacement.
array.find(predicate)call sites that can usearrayFind(array, predicate).
Why this rule existsโ
arrayFind keeps predicate-driven lookup aligned with the other ts-extras helper APIs and improves inference in generic code.
- Predicate call sites are standardized across modules.
- Result types are easier to follow in utility layers.
- Local type assertions after
findcalls are reduced.
โ Incorrectโ
const monitor = monitors.find((entry) => entry.id === targetId);
โ Correctโ
const monitor = arrayFind(monitors, (entry) => entry.id === targetId);
Behavior and migration notesโ
- Runtime behavior matches native
Array.prototype.find. - Search still returns the first matching element.
- If no element matches, the result is
undefined.
Additional examplesโ
โ Incorrect โ Additional exampleโ
const user = users.find((item) => item.id === userId);
โ Correct โ Additional exampleโ
const user = arrayFind(users, (item) => item.id === userId);
โ Correct โ Repository-wide usageโ
const firstError = arrayFind(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": "error",
},
},
];
When not to use itโ
Disable this rule if your team requires native .find() for consistency with existing shared APIs.
Package documentationโ
ts-extras package documentation:
ts-extras@0.17.x does not currently expose arrayFind in its published API, so there is no canonical source/*.ts link for this helper yet.
Reference links:
Rule catalog ID: R003