Skip to content
Sarj Code Standards

prefer-nominal-id-members

Distinguish identifier roles sharing primitive types in object types.

Why

A property annotated with a primitive type accepts identifiers from any domain that uses that type. A swap can survive type checking even when callers pass an object with named properties.

Fix

Parse identifiers with distinct branded Zod schemas at the input boundary. Use the schema output types for the corresponding properties in the domain object.

Examples

Before — flagged Primitive properties accept swapped identifiers
src/receipt.ts
interface Receipt {
accountId: string;
invoiceId: string;
}
After — preferred Branded fields keep identifier roles distinct
src/receipt.ts
import { z } from "zod";
const AccountId = z.string().brand<"AccountId">();
const InvoiceId = z.string().brand<"InvoiceId">();
interface Receipt {
accountId: z.output<typeof AccountId>;
invoiceId: z.output<typeof InvoiceId>;
}