Skip to content

enum-constructors ​

Shape.Circle(...) where Shape is only an Enum type, without constructors declared.

Why: a type exists only for the compiler, so there is nothing to call. TypeScript reports it too ("only refers to a type"); this rule comes with the fix. Guide: Building values.

Rejected (TypeScript rejects it as well, so it isn't a checked example):

ts
import type { Enum } from "@evobug_com/safe-ts-std/enum";

export type Shape = Enum<{ Circle: { radius: number }; Empty: {} }>;

export const unit = Shape.Circle({ radius: 1 });

The quick fix Declare constructors for Shape adds the line under the type, exported if the type is, and imports constructors:

✓ Accepted0 diagnostics
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";

export type Shape = Enum<{ Circle: { radius: number }; Empty: {} }>;
export const Shape = constructors<Shape>();

export const unit = Shape.Circle({ radius: 1 });
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";

export type Shape = Enum<{ Circle: { radius: number }; Empty: {} }>;
export const Shape = constructors<Shape>();

export const unit = ({ tag: "Circle", radius: 1 } satisfies Shape as Shape);

What the rule can't see: an Enum type imported from another file: the constructors belong next to the type, so declare them there.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra