A
arktype•4w ago
oddcelot

Equivalent of Object.values for unions

hi there 👋 i'm trying to extract the values of an object in order to have it as a union of options and ended up with this right here is there a better maybe more elegant solutions to this? 😅
No description
1 Reply
oddcelot
oddcelotOP•4w ago
btw: the intention was to generate a JsonSchema, but it failed as the FontWeightAliasMap.infer defines undefined in runtime usage my workaround was to redeclare this
const FontWeightNames = type.enumerated(
"thin",
"hairline",
"extra-light",
"ultra-light",
"light",
"normal",
"regular",
"book",
"medium",
"semi-bold",
"demi-bold",
"bold",
"extra-bold",
"ultra-bold",
"black",
"heavy",
"extra-black",
"ultra-black"
);

export const FontWeight = type({
$type: "'fontWeight'",
$value: type("1 <= number <= 1000").or(FontWeightNames),
});
const FontWeightNames = type.enumerated(
"thin",
"hairline",
"extra-light",
"ultra-light",
"light",
"normal",
"regular",
"book",
"medium",
"semi-bold",
"demi-bold",
"bold",
"extra-bold",
"ultra-bold",
"black",
"heavy",
"extra-black",
"ultra-black"
);

export const FontWeight = type({
$type: "'fontWeight'",
$value: type("1 <= number <= 1000").or(FontWeightNames),
});

Did you find this page helpful?