prefer-type-fest-json-object
Require TypeFest JsonObject over equivalent explicit Record<string, JsonValue> aliases.
Targeted pattern scopeโ
This rule targets direct Record<string, JsonValue> aliases used as JSON object contracts.
Record<string, JsonValue>
Broader record aliases and structurally different object constraints are intentionally left unchanged.
What this rule reportsโ
This rule reports Record<string, JsonValue> aliases that should use JsonObject.
Record<string, JsonValue>
Why this rule existsโ
JsonObject communicates intent directly and avoids repeating verbose JSON object alias patterns.
โ Incorrectโ
type Payload = Record<string, JsonValue>;
โ Correctโ
type Payload = JsonObject;
Behavior and migration notesโ
JsonObjectis equivalent in intent toRecord<string, JsonValue>for JSON object contracts.- Standardize on
JsonObjectfor shared payload/config types to avoid repeating low-level dictionary syntax. - Keep runtime validation separate; this rule only normalizes compile-time type naming.
Additional examplesโ
โ Incorrect โ Additional exampleโ
type Payload = Record<string, JsonValue>;
โ Correct โ Additional exampleโ
type Payload = JsonObject;
โ Correct โ Repository-wide usageโ
type EventAttributes = JsonObject;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-json-object": "error",
},
},
];
When not to use itโ
Disable this rule if a published API requires preserving existing alias names.
Package documentationโ
TypeFest package documentation:
Source file: source/json-value.d.ts
/**
Matches a JSON object.
This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { โฆ }`.
@category JSON
*/
Rule catalog ID: R044