prefer-type-fest-arrayable
Require TypeFest Arrayable<T> over T | T[] and T | Array<T> unions.
Targeted pattern scopeโ
This rule only matches the canonical value-or-array union spellings that TypeFest replaces with Arrayable<T>.
T | T[]T | Array<T>
Near-miss unions (extra members or mismatched element types) are excluded unless they are exact canonical forms.
What this rule reportsโ
This rule reports canonical value-or-array unions that should be rewritten as Arrayable<T>.
T | T[]T | Array<T>
Why this rule existsโ
Arrayable<T> is clearer and more consistent than repeating union patterns. It also aligns code with TypeFest utility conventions used by other rules in this plugin.
โ Incorrectโ
type Input = string | string[];
โ Correctโ
type Input = Arrayable<string>;
Behavior and migration notesโ
Arrayable<T>is the canonical form for value-or-array contracts.- It replaces both
T | T[]andT | Array<T>spelling variants. - Keep this alias in public callback and option signatures to reduce repeated union boilerplate.
Additional examplesโ
โ Incorrect โ Additional exampleโ
type Input = number | Array<number>; // Union repeated inline across modules
โ Correct โ Additional exampleโ
type Input = Arrayable<number>;
โ Correct โ Repository-wide usageโ
type QueryParam = Arrayable<string>;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-arrayable": "error",
},
},
];
When not to use itโ
Disable this rule if existing public type names must remain unchanged for compatibility.
Package documentationโ
TypeFest package documentation:
Source file: source/arrayable.d.ts
/**
Create a type that represents either the value or an array of the value.
@see {@link Promisable}
@example
```
import type {Arrayable} from 'type-fest';
function bundle(input: string, output: Arrayable<string>) {
const outputList = Array.isArray(output) ? output : [output];
// โฆ
for (const output of outputList) {
console.log(`write ${input} to: ${output}`);
}
}
bundle('src/index.js', 'dist/index.js');
bundle('src/index.js', ['dist/index.cjs', 'dist/index.mjs']);
```
@category Array
*/
Rule catalog ID: R036