Handling Unexpected JSON Enum Values in TypeScript

I want to parse a json response. It has a property status which can be of 3 possible values: "completed", "in_progress", "queued".

I create my schema and enum that represents these 3 values:

export enum Status {
  Completed = 'completed',
  InProgress = 'in_progress',
  Queued = 'queued',
}

export const Response = S.Struct({
  status: S.Enums(StepStatus),
});


Now the API I'm using adds an additional property without me knowing: "pending".

How would I create my schema so that it becomes "resistant" to this change?

* How could I give status the value null if any of the Enum cases doesn't match?
* How could I give it a default Enum case if any cases doesn't match, e.g. Unknown?
Was this page helpful?