Skip to main content

prefer-type-fest-unknown-map

Require TypeFest UnknownMap over ReadonlyMap<unknown, unknown>.

Targeted pattern scopeโ€‹

This rule targets explicit unknown-map spellings that TypeFest standardizes as UnknownMap.

  • ReadonlyMap<unknown, unknown> type references.

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

What this rule reportsโ€‹

This rule reports unknown-map type forms that should migrate to UnknownMap.

  • ReadonlyMap<unknown, unknown> type references.

Why this rule existsโ€‹

UnknownMap communicates intent directly and keeps unknown-container aliases consistent with other TypeFest-first conventions in this plugin.

โŒ Incorrectโ€‹

type Meta = ReadonlyMap<unknown, unknown>;

โœ… Correctโ€‹

type Meta = UnknownMap;

Behavior and migration notesโ€‹

  • UnknownMap is a canonical alias for maps with unknown key/value pairs.
  • Normalize map ingress contracts to one alias instead of repeating ReadonlyMap<unknown, unknown>.
  • Narrow key/value types at use sites after validating actual runtime shapes.

Additional examplesโ€‹

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

type Store = ReadonlyMap<unknown, unknown>;

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

type Store = UnknownMap;

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

type Metadata = UnknownMap;

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

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

When not to use itโ€‹

Disable this rule if published contracts must preserve existing map alias names.

Package documentationโ€‹

TypeFest package documentation:

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

/**
* Represents a map with `unknown` key and value.
*
* Use case: You want a type that all maps can be assigned to, but you don't
* care about the value.
*
* @category Type
*
* @example
* ```
* import type {UnknownMap} from 'type-fest';
*
* type IsMap<T> = T extends UnknownMap ? true : false;
*
* type A = IsMap<Map<string, number>>;
* //=> true
*
* type B = IsMap<ReadonlyMap<number, string>>;
* //=> true
*
* type C = IsMap<string>;
* //=> false
* ```;
*/

Rule catalog ID: R070

Further readingโ€‹

Adoption resourcesโ€‹