prefer-type-fest-primitive
Require TypeFest Primitive over explicit unions of primitive keyword types.
Targeted pattern scopeโ
This rule targets full primitive keyword unions used as standalone scalar aliases.
What this rule reportsโ
- Unions composed of all primitive keyword types:
stringnumberbigintbooleansymbolnullundefined
Why this rule existsโ
Primitive communicates intent directly and avoids repeating a long union in multiple places.
โ Incorrectโ
type PrimitiveValue = string | number | bigint | boolean | symbol | null | undefined;
โ Correctโ
type PrimitiveValue = Primitive;
Behavior and migration notesโ
Primitivecovers all JS primitive categories:string,number,bigint,boolean,symbol,null,undefined.- This rule targets unions that include the complete primitive set.
- Keep explicit subsets when domain semantics require only a subset of primitive categories.
Additional examplesโ
โ Incorrect โ Additional exampleโ
type Scalar = string | number | bigint | boolean | symbol | null | undefined;
โ Correct โ Additional exampleโ
type Scalar = Primitive;
โ Correct โ Repository-wide usageโ
type LeafValue = Primitive;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-primitive": "error",
},
},
];
When not to use itโ
Disable this rule if explicit primitive unions are part of a published API contract.
Package documentationโ
TypeFest package documentation:
Source file: source/primitive.d.ts
/**
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
@category Type
*/
Rule catalog ID: R053