Skip to content

enum-method-receiver ​

A call of an enum method that the build can't turn into a call of the enum's table: the value's type isn't declared anywhere the checker follows, the call is written in a form the rewrite doesn't take, it is in a Vue template, or the method is taken off its value. On by default, as an error.

Why: Enum<V, M> declares methods, but the values stay plain objects with no methods of their own. The build turns job.describe() into Job.describe(job) where the declarations say job is a Job: a parameter, a local, a field, an item of a declared list, a function's declared return type, a constructor's result, a match handler's value, variant(...)'s result. Anywhere else nothing rewrites the call, and it fails with "job.describe is not a function". Guide: Methods on an enum.

What the checker can't follow (a value picked by ?: or ??, a value from an untyped function, a cast), a form the rewrite doesn't take (job.describe?.(), a call inside a longer optional chain such as a?.b.describe()), a call in a Vue template, and a method read without a call (const f = job.describe) are reported.

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

export type Job = Enum<{ Queued: {}; Failed: { reason: string } }, { readonly describe: () => string }>;
export const Job = constructors<Job>().impl({
  describe: (job) => match(job, { Queued: () => "queued", Failed: ({ reason }) => `failed: ${reason}` }),
});

export function headline(jobs: readonly Job[]): string {
  const picked = jobs.length > 0 ? jobs[0] : undefined;
  const describe = Job.Queued().describe;
  return picked?.describe() ?? describe();
}
ts
import type { Data as __EnumData } from "@evobug_com/safe-ts-std/enum"; import { constructors, type Enum, match } from "@evobug_com/safe-ts-std/enum";

export type Job = Enum<{ Queued: {}; Failed: { reason: string } }, { readonly describe: () => string }>;
export const Job = constructors<Job>().impl({
  describe: (job) => match(job, { Queued: () => "queued", Failed: ({ reason }) => `failed: ${reason}` }),
});

export function headline(jobs: readonly Job[]): string {
  const picked = jobs.length > 0 ? jobs[0] : undefined;
  const describe = ({ tag: "Queued" } satisfies __EnumData<Job> as Job).describe;
  return picked?.describe() ?? describe();
}

✅ Accepted: the type declared where the value is held, the method called where it is used

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

export type Job = Enum<{ Queued: {}; Failed: { reason: string } }, { readonly describe: () => string }>;
export const Job = constructors<Job>().impl({
  describe: (job) => match(job, { Queued: () => "queued", Failed: ({ reason }) => `failed: ${reason}` }),
});

export function headline(jobs: readonly Job[]): string {
  const picked: Option<Job> = jobs.length > 0 ? jobs[0] : undefined;
  return picked?.describe() ?? Job.Queued().describe();
}
ts
import type { Data as __EnumData } from "@evobug_com/safe-ts-std/enum"; import { constructors, type Enum, match } from "@evobug_com/safe-ts-std/enum";
import type { Option } from "@evobug_com/safe-ts-std/result";

export type Job = Enum<{ Queued: {}; Failed: { reason: string } }, { readonly describe: () => string }>;
export const Job = constructors<Job>().impl({
  describe: (job): string => match(job, { Queued: () => "queued", Failed: ({ reason }) => `failed: ${reason}` }),
});

export function headline(jobs: readonly Job[]): string {
  const picked: Option<Job> = jobs.length > 0 ? jobs[0] : undefined;
  return (picked == null ? undefined : Job.describe(picked)) ?? Job.describe(({ tag: "Queued" } satisfies __EnumData<Job> as Job));
}

The table form is the same function and always works: Job.describe(picked). Pass it where a function is wanted (jobs.map(Job.describe)).

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