Skip to content

Schema

Description

Schema type builder.

Import

import { s } from "dreamkit";

Definition

import type {
BoolType,
NumberType,
ObjectType,
StringType,
FileType,
ArrayType,
Type,
} from "dreamkit";
declare const s: {
title(value: string): typeof s;
object(props: Record<string, Type>): ObjectType;
array(type: Type): ArrayType;
string(): StringType;
number(): NumberType;
bool(): BoolType;
file(): FileType;
};

Examples

Validate

import { $route, s, type InferType } from "dreamkit";
const type = s.object({
name: s.string().min(3),
enabled: s.bool(),
});
export default $route.path("/").create(() => {
const value: InferType<typeof type> = {
name: "ab",
enabled: true,
};
return (
<>
<p>validate: {JSON.stringify(type.validate(value), null, 2)}</p>
</>
);
});