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
nullexclusion. - Simpler
unknown extends T ? true : falsehelpers are ignored because they also matchany. - Autofix is skipped when
IsUnknownis 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