Skip to main content

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:
    • string
    • number
    • bigint
    • boolean
    • symbol
    • null
    • undefined

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โ€‹

  • Primitive covers 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

Further readingโ€‹

Adoption resourcesโ€‹