prefer-type-fest-json-value
Prefers TypeFest JsonObject for serialization-bound string-keyed record contracts.
Targeted pattern scopeโ
This rule targets boundary-layer Record<string, unknown/any> payload aliases that are intended to represent JSON-compatible values.
- Payload/context-like contract aliases using
Record<string, unknown>/Record<string, any>in JSON boundary folders.
General-purpose records outside configured JSON boundaries are intentionally excluded.
What this rule reportsโ
This rule reports boundary payload aliases that should use JsonObject.
- Payload/context-like contract aliases using
Record<string, unknown>/Record<string, any>in JSON boundary folders.
Why this rule existsโ
Serialization boundaries should declare JSON-compatible intent directly so type safety and runtime assumptions stay aligned.
โ Incorrectโ
type Payload = Record<string, unknown>;
โ Correctโ
type Payload = JsonObject;
Behavior and migration notesโ
JsonObjectmodels JSON-compatible object payloads with string keys.- Use
JsonObjectwhen your boundary contract must stay object-shaped. - Replace open-ended
Record<string, unknown>/anyboundary contracts withJsonObjectwhen schema intent is serialization.
Additional examplesโ
โ Incorrect โ Additional exampleโ
type ConfigSnapshot = Record<string, unknown>;
โ Correct โ Additional exampleโ
type ConfigSnapshot = JsonObject;
โ Correct โ Repository-wide usageโ
type CacheEntry = JsonObject;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-json-value": "error",
},
},
];
When not to use itโ
Disable this rule if boundary contracts intentionally allow non-JSON runtime values.
Package documentationโ
TypeFest package documentation:
Source file: source/json-value.d.ts
/**
Matches any valid JSON value.
@see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
@category JSON
*/
Rule catalog ID: R046