Skip to content
Sarj Code Standards

prefer-named-literal-union

Name repeated inline string literal unions in a module.

Why

Repeated literal unions can drift when a domain gains or loses a value.

Fix

Declare the domain in one type alias and reference that alias at each use.

Examples

Before — flagged Name the shared draft state
src/drafts.ts
interface Draft {
state: "queued" | "running" | "done";
previousState: "queued" | "running" | "done";
}
After — preferred Use one state alias
src/drafts.ts
type DraftState = "queued" | "running" | "done";
interface Draft {
state: DraftState;
previousState: DraftState;
}