Skip to content

isValidJobStatus

function isValidJobStatus(value): value is JobStatusType;

Defined in: packages/core/src/jobs/guards.ts:73

Type guard to check if a value is a valid job status.

Validates that a value is one of the five valid job statuses: 'pending', 'processing', 'completed', 'failed', or 'cancelled'. Useful for runtime validation of user input or external data.

ParameterTypeDescription
valueunknownThe value to check

value is JobStatusType

true if the value is a valid JobStatusType, narrowing the type

function filterByStatus(status: string) {
  if (!isValidJobStatus(status)) {
    throw new Error(`Invalid status: ${status}`);
  }
  // TypeScript knows status is JobStatusType here
  return db.jobs.find({ status });
}
const statusFromApi = externalData.status;

if (isValidJobStatus(statusFromApi)) {
  job.status = statusFromApi;
} else {
  job.status = JobStatus.PENDING;
}