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) => Tconstructor 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 produceT.- 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