prefer-type-fest-has-writable-keys
Require TypeFest HasWritableKeys<T> over WritableKeysOf<T> emptiness checks.
Targeted pattern scopeโ
This rule reports exact WritableKeysOf<T> extends never ? false : true checks when WritableKeysOf is imported from type-fest.
It supports direct, aliased, and namespace-qualified TypeFest imports.
What this rule reportsโ
This rule reports manual writable-key existence checks that can be replaced by HasWritableKeys<T>.
Why this rule existsโ
HasWritableKeys<T> makes writable-key existence intent explicit and avoids repeating TypeFest helper compositions in user code.
โ Incorrectโ
import type { WritableKeysOf } from "type-fest";
type Result<T extends object> = WritableKeysOf<T> extends never ? false : true;
โ Correctโ
import type { HasWritableKeys } from "type-fest";
type Result<T extends object> = HasWritableKeys<T>;
Behavior and migration notesโ
- The
WritableKeysOfreference must resolve to atype-festimport. - The rule only reports the exact
extends never ? false : trueshape. - Inverted checks and custom fallback branches are ignored.
- Autofix is skipped when
HasWritableKeysis shadowed in the local scope.
Additional examplesโ
โ Incorrect โ Namespace importโ
import type * as TypeFest from "type-fest";
type Result<T extends object> = TypeFest.WritableKeysOf<T> extends never ? false : true;
โ Correct โ Namespace importโ
import type { HasWritableKeys } from "type-fest";
type Result<T extends object> = HasWritableKeys<T>;
โ Correct โ Inverted checkโ
import type { WritableKeysOf } from "type-fest";
type Result<T extends object> = WritableKeysOf<T> extends never ? true : false;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-has-writable-keys": "error",
},
},
];
When not to use itโ
Disable this rule if a public helper must keep the expanded TypeFest composition for compatibility or documentation reasons.
Package documentationโ
TypeFest package documentation:
Source file: source/has-writable-keys.d.ts
Rule catalog ID: R120