Skip to main content

prefer-type-fest-constructor

Require TypeFest Constructor over explicit constructor signatures.

Targeted pattern scopeโ€‹

This rule reports explicit new (...args) => T signatures and prefers Constructor<T> for newable class contracts.

What this rule reportsโ€‹

  • new (...args) => T constructor type signatures.

Detection boundariesโ€‹

  • โœ… Reports explicit non-abstract constructor signatures in type positions.
  • โŒ Does not auto-fix when argument-generic relationships need manual preservation.

Why this rule existsโ€‹

Constructor<T> is a canonical alias for class factory contracts.

Using one alias across modules keeps dependency-injection and class-registry types uniform.

โŒ Incorrectโ€‹

type ExplicitCtor = new (host: string, port: number) => Service;

โœ… Correctโ€‹

import type { Constructor } from "type-fest";

type ServiceCtor = Constructor<Service>;

Behavior and migration notesโ€‹

  • Constructor<T> expresses "newable" class values that produce T.
  • Preserve specialized argument tuples with wrapper types when replacing explicit signatures.
  • Prefer this alias in public APIs to avoid repeated constructor signature boilerplate.

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

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

When not to use itโ€‹

Disable this rule if your codebase intentionally prefers explicit constructor signatures over TypeFest aliases.

Package documentationโ€‹

TypeFest package documentation:

Source file: source/basic.d.ts

/**
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).

@category Class
*/

Rule catalog ID: R039

Further readingโ€‹

Adoption resourcesโ€‹