Skip to main content

prefer-type-fest-unknown-record

Prefers UnknownRecord from TypeFest over Record<string, unknown> in architecture-critical layers.

Targeted pattern scopeโ€‹

This rule targets explicit unknown-record spellings that TypeFest standardizes as UnknownRecord.

  • Record<string, unknown> type references in configured boundary paths (for example shared contracts and IPC-adjacent layers).

Other collection contracts are left alone unless they match the exact unknown collection form listed below.

What this rule reportsโ€‹

This rule reports unknown-record type forms that should migrate to UnknownRecord.

  • Record<string, unknown> type references in configured boundary paths (for example shared contracts and IPC-adjacent layers).

Why this rule existsโ€‹

UnknownRecord conveys intent directly and keeps boundary contracts consistent with TypeFest-first typing conventions.

โŒ Incorrectโ€‹

type Payload = Record<string, unknown>;

โœ… Correctโ€‹

type Payload = UnknownRecord;

Behavior and migration notesโ€‹

  • UnknownRecord is the canonical dictionary-like unknown-object alias in type-fest.
  • Standardize boundary object contracts on UnknownRecord instead of repeating Record<string, unknown>.
  • Keep runtime validation and field narrowing at call sites that consume unknown records.

Additional examplesโ€‹

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

type Input = Record<string, unknown>;

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

type Input = UnknownRecord;

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

type EventPayload = UnknownRecord;

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

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

When not to use itโ€‹

Disable this rule if a public contract requires preserving existing record alias names.

Package documentationโ€‹

TypeFest package documentation:

Source file: source/unknown-record.d.ts

/**
Represents an object with `unknown` value. You probably want this instead of `{}`.

Use case: You have an object whose keys and values are unknown to you.

@example
```
import type {UnknownRecord} from 'type-fest';

function toJson(object: UnknownRecord) {
return JSON.stringify(object);
}

toJson({hello: 'world'}); // Ok

function isObject(value: unknown): value is UnknownRecord {
return typeof value === 'object' && value !== null;
}

const value: unknown = {hello: 'world'};

if (isObject(value)) {
const v = value;
//=> UnknownRecord
}
```

@category Type
@category Object
*/

Rule catalog ID: R071

Further readingโ€‹

Adoption resourcesโ€‹