Manually declare output type for a validation

Hello - I'm working on a library that emits types inferred from arktype validations.

I want the inferred output type to use a named type (which i also export), instead of the literal inferred value of that type.

So:
// not this
fruit: "apple" | "banana" | "cherry";
// instead I want this
fruit: Fruit,


Given the following code
export const FRUITS = ["apple", "banana", "cherry"] as const;
export type Fruit = (typeof FRUITS)[number];
const FruitSchema = type("===", ...FRUITS);

export const FoodSchema = type({
    fruit: FruitSchema,
});

export type Food = typeof FoodSchema.infer;


I get the following output (built with tsdown):
import * as arktype_internal_methods_object_ts0 from "arktype/internal/methods/object.ts";

//#region index.d.ts
declare const FRUITS: readonly ["apple", "banana", "cherry"];
type Fruit = (typeof FRUITS)[number];
declare const FoodSchema: arktype_internal_methods_object_ts0.ObjectType<{
  fruit: "apple" | "banana" | "cherry";
}, {}>;
type Food = typeof FoodSchema.infer;
//# sourceMappingURL=index.d.ts.map

//#endregion
export { FRUITS, Food, FoodSchema, Fruit };
//# sourceMappingURL=index.d.mts.map


Which makes complete sense, but wondering if theres something like Drizzle ORM's. .$type<Fruit> to get this behavior.
Was this page helpful?