`Schema.pickLiteral` Does Not Copy Custom Annotations
Hi, is it correct behavior that
Schema.pickLiteralSchema.pickLiteral does not copy (custom) annotations of the source Literal? Not sure whether this is a bug or by design.export namespace LiteralEnum {
export const LabelId = Symbol.for("LiteralEnumLabel");
export const make = <const Literals extends Array.NonEmptyArray<SchemaAST.LiteralValue>>(
literals: Literals,
label: (input: Literals[number]) => string,
) => Schema.Literal(...literals).annotations({ [LabelId]: label });
export const getLabelAnnotation = <A extends Schema.Schema.Any>(schema: A) =>
pipe(
schema.ast,
getAnnotation(LabelId),
Option.filter((value) => typeof value === "function"),
Option.getOrElse(() => (input: unknown) => `${input}`),
);
export const getLabel =
<A extends Schema.Schema.Any>(schema: A) =>
(input: Schema.Schema.Type<A>) => {
const fn = getLabelAnnotation(schema);
return fn(input);
};
}
export type Platform = typeof Platform.Type;
export const Platform = LiteralEnum.make(["amazon", "shopify"], (input) => {
switch (input) {
case "amazon":
return "Amazon";
case "shopify":
return "Shopify";
}
});
const TestLiteral = Platform.pipe(Schema.pickLiteral("amazon"));
const platform: Platform = "amazon";
const platformLabel = LiteralEnum.getLabel(TestLiteral)(platform); // expected to return Amazon with capital A but returns amazon, meaning the label annotation is not present
const working = LiteralEnum.getLabel(Platform)(platform); // correctly returns Amazon with capital Aexport namespace LiteralEnum {
export const LabelId = Symbol.for("LiteralEnumLabel");
export const make = <const Literals extends Array.NonEmptyArray<SchemaAST.LiteralValue>>(
literals: Literals,
label: (input: Literals[number]) => string,
) => Schema.Literal(...literals).annotations({ [LabelId]: label });
export const getLabelAnnotation = <A extends Schema.Schema.Any>(schema: A) =>
pipe(
schema.ast,
getAnnotation(LabelId),
Option.filter((value) => typeof value === "function"),
Option.getOrElse(() => (input: unknown) => `${input}`),
);
export const getLabel =
<A extends Schema.Schema.Any>(schema: A) =>
(input: Schema.Schema.Type<A>) => {
const fn = getLabelAnnotation(schema);
return fn(input);
};
}
export type Platform = typeof Platform.Type;
export const Platform = LiteralEnum.make(["amazon", "shopify"], (input) => {
switch (input) {
case "amazon":
return "Amazon";
case "shopify":
return "Shopify";
}
});
const TestLiteral = Platform.pipe(Schema.pickLiteral("amazon"));
const platform: Platform = "amazon";
const platformLabel = LiteralEnum.getLabel(TestLiteral)(platform); // expected to return Amazon with capital A but returns amazon, meaning the label annotation is not present
const working = LiteralEnum.getLabel(Platform)(platform); // correctly returns Amazon with capital A