prefer-type-fest-readonly-date
Prefer ReadonlyDate from type-fest 6. Describe a readonly view of a Date that omits its setters.
Targeted pattern scopeโ
The outer Readonly, inner Omit, and Date must resolve to their global types. The omitted keys must match exactly set${string}.
What this rule reportsโ
The rule recognizes the readonly projection even when a project augments the global Date with named properties or additional setter methods.
Why this rule existsโ
Readonly<Date> keeps callable setters such as setTime. Removing all setter keys gives a read-only interface and also removes setters added through declaration merging.
โ Incorrectโ
type CalendarDate = Readonly<Omit<Date, `set${string}`>>;
โ Correctโ
import type { ReadonlyDate } from "type-fest";
type CalendarDate = ReadonlyDate;
Behavior and migration notesโ
The rule requires type information and skips a global Date with an index signature because Omit can lose the types of individual properties. This type changes compile-time access to the object. Runtime mutation is still possible. A comment inside the matched expression or a conflicting local name prevents an automatic edit.
Package documentationโ
TypeFest package documentation:
Rule catalog ID: R147