For the types I am working on that will undergo serialization, it is crucial to confirm with certainty that a property falls within "the allowed values" category.
export const operationTypes = ["a", "b"]
export type Operation = {
type: string in operationTypes // <-- this should illustrate my intention
}
// Ensure during parsing that the operation type is a valid string
function validateOperationType(operation: Operation) {
return operationTypes.includes(operation.type)
}
In simple terms, the "type" attribute in Operation has to match one of the predefined values in an array. And the existence of this value in the array must be verifiable (during runtime).
How can this goal be achieved?