Skip to content

TypeScript Consumer Pattern

A TypeScript consumer should separate parsing from the application decision.

type KnownStatus =
| "PASS"
| "FAIL"
| "INCOMPLETE"
| "UNKNOWN";
type VerificationResult = {
status: KnownStatus;
artifactId?: string;
raw: Record<string, unknown>;
};
function parseVerificationResult(
payload: Record<string, unknown>
): VerificationResult {
const candidate = payload.status;
const known: KnownStatus[] = [
"PASS",
"FAIL",
"INCOMPLETE",
"UNKNOWN",
];
const status: KnownStatus =
typeof candidate === "string" &&
known.includes(candidate as KnownStatus)
? (candidate as KnownStatus)
: "UNKNOWN";
return {
status,
artifactId:
typeof payload.artifact_id === "string"
? payload.artifact_id
: undefined,
raw: payload,
};
}
function mayAccept(
result: VerificationResult
): boolean {
return result.status === "PASS";
}

Do not let an unknown enum value fall through to a default success path.

When the authoritative DigiEmu contract changes, update the parser and tests before enabling the new state in production.