Skip to main content

Type alias: SchemaOf<T>

SchemaOf<T>: ObjectValidator<T>

An alias of ObjectValidator with a name more common among object validation libraries. This is the type of a schema after using s.object({ ... })


import { s, SchemaOf } from '@sapphire/shapeshift';

interface IIngredient {
ingredientId: string | undefined;
name: string | undefined;

interface IInstruction {
instructionId: string | undefined;
message: string | undefined;

interface IRecipe {
recipeId: string | undefined;
title: string;
description: string;
instructions: IInstruction[];
ingredients: IIngredient[];

type InstructionSchemaType = SchemaOf<IInstruction>;
// Expected Type: ObjectValidator<IInstruction>

type IngredientSchemaType = SchemaOf<IIngredient>;
// Expected Type: ObjectValidator<IIngredient>

type RecipeSchemaType = SchemaOf<IRecipe>;
// Expected Type: ObjectValidator<IRecipe>

const instructionSchema: InstructionSchemaType = s.object({
instructionId: s.string.optional,
message: s.string

const ingredientSchema: IngredientSchemaType = s.object({
ingredientId: s.string.optional,
name: s.string

const recipeSchema: RecipeSchemaType = s.object({
recipeId: s.string.optional,
title: s.string,
description: s.string,
instructions: s.array(instructionSchema),
ingredients: s.array(ingredientSchema)

Type parameters

Type parameter
T extends object