Skip to main content

TypeOf<S>

Types can be inferred based on validators:

import { nonEmpty, minStringLength, nil,, object, string } from '@typeofweb/schema';
import type { TypeOf } from '@typeofweb/schema';

const blogSchema = object({
title: (string, minStringLength(10)),
description: (string, nil),
href: (string, nil, nonEmpty),
rssUrl: (string, nil, nonEmpty),
})();

type Blog = TypeOf<typeof blogSchema>;
// type Blog = {
// readonly title: string;
// readonly description?: string | null | undefined;
// readonly href?: string | null | undefined;
// readonly rssUrl?: string | null | undefined;
// }