Skip to main content

prefer-type-fest-unknown-set

Require TypeFest UnknownSet over ReadonlySet<unknown>.

Targeted pattern scopeโ€‹

This rule targets explicit unknown-set spellings that TypeFest standardizes as UnknownSet.

  • ReadonlySet<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-set type forms that should migrate to UnknownSet.

  • ReadonlySet<unknown> type references.

Why this rule existsโ€‹

UnknownSet provides a clearer shared alias for unknown-valued sets and keeps TypeFest utility usage consistent with other rules in this plugin.

โŒ Incorrectโ€‹

type Keys = ReadonlySet<unknown>;

โœ… Correctโ€‹

type Keys = UnknownSet;

Behavior and migration notesโ€‹

  • UnknownSet is the canonical alias for unknown-valued readonly sets.
  • Normalize ReadonlySet<unknown> usage to one alias to avoid duplicate naming patterns.
  • Narrow member types after membership checks in consuming code.

Additional examplesโ€‹

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

type Keys = ReadonlySet<unknown>;

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

type Keys = UnknownSet;

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

type DynamicSet = UnknownSet;

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

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

When not to use itโ€‹

Disable this rule if exported type names must remain unchanged.

Package documentationโ€‹

TypeFest package documentation:

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

/**
Represents a set with `unknown` value.

Use case: You want a type that all sets can be assigned to, but you don't care about the value.

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

type IsSet<T> = T extends UnknownSet ? true : false;

type A = IsSet<Set<string>>;
//=> true

type B = IsSet<ReadonlySet<number>>;
//=> true

type C = IsSet<string>;
//=> false
```

@category Type
*/

Rule catalog ID: R072

Further readingโ€‹

Adoption resourcesโ€‹