Skip to main content

prefer-type-fest-is-unknown

Require TypeFest IsUnknown<T> over manual unknown conditional type guards.

Targeted pattern scopeโ€‹

This rule reports exact conditional type guards shaped like unknown extends T ? [T] extends [null] ? false : true : false.

What this rule reportsโ€‹

This rule reports manual unknown detection helpers that can be replaced by IsUnknown<T>.

  • unknown extends T ? [T] extends [null] ? false : true : false

Why this rule existsโ€‹

IsUnknown<T> documents the intent directly and avoids repeating a brittle conditional type trick across a codebase.

โŒ Incorrectโ€‹

type Result<T> = unknown extends T ? [T] extends [null] ? false : true : false;

โœ… Correctโ€‹

type Result<T> = IsUnknown<T>;

Behavior and migration notesโ€‹

  • The rule intentionally requires the exact tuple-wrapped null exclusion.
  • Simpler unknown extends T ? true : false helpers are ignored because they also match any.
  • Autofix is skipped when IsUnknown is shadowed in the local scope.

Additional examplesโ€‹

โœ… Correct โ€” Existing utilityโ€‹

type Result<T> = IsUnknown<T>;

โœ… Correct โ€” Simpler but not equivalentโ€‹

type Result<T> = unknown extends T ? true : false;

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

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

When not to use itโ€‹

Disable this rule if a public type alias must preserve a hand-written conditional for compatibility documentation.

Package documentationโ€‹

TypeFest package documentation:

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

Rule catalog ID: R111

Further readingโ€‹

Adoption resourcesโ€‹