prefer-type-fest-unknown-array
Require TypeFest UnknownArray over readonly unknown[] and ReadonlyArray<unknown>.
Targeted pattern scopeโ
This rule targets explicit unknown-array spellings that TypeFest standardizes as UnknownArray.
readonly unknown[]ReadonlyArray<unknown>
Other collection contracts are left alone unless they match the exact unknown collection form listed below.
What this rule reportsโ
This rule reports unknown-array type forms that should migrate to UnknownArray.
readonly unknown[]ReadonlyArray<unknown>
Why this rule existsโ
UnknownArray provides a clearer, shared alias for unknown element arrays and keeps utility-type usage consistent with other TypeFest-first conventions.
โ Incorrectโ
type Values = readonly unknown[];
โ Correctโ
type Values = UnknownArray;
Behavior and migration notesโ
UnknownArrayis the canonical alias for readonly unknown-element arrays intype-feststyle.- This rule normalizes
readonly unknown[]andReadonlyArray<unknown>into one shared name. - Use this alias for untyped collection ingress points before narrowing.
Additional examplesโ
โ Incorrect โ Additional exampleโ
type Input = readonly unknown[];
โ Correct โ Additional exampleโ
type Input = UnknownArray;
โ Correct โ Repository-wide usageโ
type PayloadList = UnknownArray;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-unknown-array": "error",
},
},
];
When not to use itโ
Disable this rule if external API signatures must preserve existing alias names.
Package documentationโ
TypeFest package documentation:
Source file: source/unknown-array.d.ts
/**
Represents an array with `unknown` value.
Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
@example
```
import type {UnknownArray} from 'type-fest';
type IsArray<T> = T extends UnknownArray ? true : false;
type A = IsArray<['foo']>;
//=> true
type B = IsArray<readonly number[]>;
//=> true
type C = IsArray<string>;
//=> false
```
@category Type
@category Array
*/
Rule catalog ID: R069