Skip to main content

prefer-type-fest-json-array

Require TypeFest JsonArray over explicit JsonValue array-union aliases.

Targeted pattern scopeโ€‹

This rule matches explicit JSON array alias spellings where JsonArray communicates intent directly.

  • JsonValue[] | readonly JsonValue[]
  • Array<JsonValue> | ReadonlyArray<JsonValue>

This rule intentionally excludes other array aliases and non-JSON payload array forms.

What this rule reportsโ€‹

This rule reports explicit JsonValue array alias forms that should use JsonArray.

  • JsonValue[] | readonly JsonValue[]
  • Array<JsonValue> | ReadonlyArray<JsonValue>

Why this rule existsโ€‹

JsonArray communicates JSON array intent directly and avoids repeating equivalent array union shapes.

โŒ Incorrectโ€‹

type Payload = JsonValue[] | readonly JsonValue[];

โœ… Correctโ€‹

type Payload = JsonArray;

Behavior and migration notesโ€‹

  • JsonArray is the canonical alias for JSON arrays in type-fest.
  • Keep JsonValue[] | readonly JsonValue[] usage out of shared contracts to avoid duplicate representations.
  • Prefer one canonical alias per concept to reduce type alias drift across packages.

Additional examplesโ€‹

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

type Payload = Array<JsonValue>;

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

type Payload = JsonArray;

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

type SerializedRows = JsonArray;

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-json-array": "error",
},
},
];

When not to use itโ€‹

Disable this rule if public APIs must preserve existing custom alias names for compatibility.

Package documentationโ€‹

TypeFest package documentation:

Source file: source/json-value.d.ts

/**
Matches a JSON array.

@category JSON
*/

Rule catalog ID: R043

Further readingโ€‹

Adoption resourcesโ€‹