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โ
UnknownMapis 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.
@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
```
@category Type
*/
Rule catalog ID: R070