Skip to main content

prefer-type-fest-abstract-constructor

Require TypeFest AbstractConstructor over explicit abstract constructor signatures.

Targeted pattern scopeโ€‹

This rule reports explicit abstract new (...args) => T signatures and prefers AbstractConstructor<T> for abstract class constructor contracts.

What this rule reportsโ€‹

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

Detection boundariesโ€‹

  • โœ… Reports explicit abstract constructor signatures used directly in type positions.
  • โŒ Does not auto-fix when generic parameter mapping is ambiguous.

Why this rule existsโ€‹

AbstractConstructor<T> gives one canonical representation for abstract constructable class contracts.

When teams mix explicit constructor signatures and helper aliases, higher-order APIs that accept class references become harder to standardize.

โŒ Incorrectโ€‹

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

โœ… Correctโ€‹

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

type ServiceAbstractCtor = AbstractConstructor<Service>;

Behavior and migration notesโ€‹

  • AbstractConstructor<T> models class values that cannot be instantiated directly but can be subclassed.
  • If your explicit signature encoded argument constraints, preserve them by adding a dedicated wrapper type.
  • Prefer canonical alias usage in plugin/public APIs that accept abstract class constructors.

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

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

When not to use itโ€‹

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

Package documentationโ€‹

TypeFest package documentation:

Source file: source/basic.d.ts

/**
Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html#abstract-construct-signatures) constructor.

@category Class
*/

Rule catalog ID: R035

Further readingโ€‹

Adoption resourcesโ€‹