Skip to main content

prefer-type-fest-writable-keys-of

Require TypeFest WritableKeysOf<T> over expanded writable-key extraction helpers.

Targeted pattern scopeโ€‹

This rule reports the exact TypeFest composition T extends unknown ? Exclude<keyof T, ReadonlyKeysOf<T>> : never.

It supports direct, aliased, and namespace-qualified TypeFest imports for ReadonlyKeysOf.

What this rule reportsโ€‹

This rule reports expanded writable-key extraction helpers that can be replaced by WritableKeysOf<T>.

Why this rule existsโ€‹

WritableKeysOf<T> is the canonical TypeFest utility for extracting writable keys. Using it directly makes modifier introspection clearer and avoids repeating TypeFest helper compositions.

โŒ Incorrectโ€‹

import type { ReadonlyKeysOf } from "type-fest";

type Result<Type extends object> = Type extends unknown
? Exclude<keyof Type, ReadonlyKeysOf<Type>>
: never;

โœ… Correctโ€‹

import type { WritableKeysOf } from "type-fest";

type Result<Type extends object> = WritableKeysOf<Type>;

Behavior and migration notesโ€‹

  • The ReadonlyKeysOf reference must resolve to a type-fest import.
  • The rule only reports the exact distributive exclusion shape used by TypeFest.
  • Non-distributive exclusions are ignored because they can differ for union types.
  • Autofix is skipped when WritableKeysOf is shadowed in the local scope.

Additional examplesโ€‹

โŒ Incorrect โ€” Namespace importโ€‹

import type * as TypeFest from "type-fest";

type Result<Type extends object> = Type extends unknown
? Exclude<keyof Type, TypeFest.ReadonlyKeysOf<Type>>
: never;

โœ… Correct โ€” Namespace importโ€‹

import type { WritableKeysOf } from "type-fest";

type Result<Type extends object> = WritableKeysOf<Type>;

โœ… Correct โ€” Non-distributive helperโ€‹

import type { ReadonlyKeysOf } from "type-fest";

type Result<Type extends object> = Exclude<keyof Type, ReadonlyKeysOf<Type>>;

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-writable-keys-of": "error",
},
},
];

When not to use itโ€‹

Disable this rule if a public helper must intentionally expose the expanded exclusion implementation.

Package documentationโ€‹

TypeFest package documentation:

Source file: source/writable-keys-of.d.ts

Rule catalog ID: R124

Further readingโ€‹

Adoption resourcesโ€‹