A
arktype2mo ago
anbech.

Get values from type.enumerated?

const ValidationErrorCodes = type.enumerated(
"INVALID_EMAIL",
"MISSING_FIELD",
"INVALID_FORMAT"
);
const ValidationErrorCodes = type.enumerated(
"INVALID_EMAIL",
"MISSING_FIELD",
"INVALID_FORMAT"
);
Is it possible to extract the values? e.g. so I can use them in say a foreach loop?
2 Replies
TizzySaurus
TizzySaurus2mo ago
I think that is possible, but I don't remember how. I guess the easier way would be
const values = ["INVALID_EMAIL", ...] as const;
const ValidationErrorCodes = type.enumerated(...values);
const values = ["INVALID_EMAIL", ...] as const;
const ValidationErrorCodes = type.enumerated(...values);
ssalbdivad
ssalbdivad2mo ago
Yeah, @TizzySaurus's suggestion is best in terms of clarity and probably a good idea from a design perspective as well. However, if you really need the literal values and can't define them beforehand, you could do something like this:
ValidationErrorCodes.internal.branches.map((b) => b.assertHasKind("unit").unit)
ValidationErrorCodes.internal.branches.map((b) => b.assertHasKind("unit").unit)

Did you find this page helpful?