felixmosh / types-joi

TypeScript types for joi (Object schema description language and validator for JavaScript objects) https://github.com/hapijs/joi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

types-joi

TypeScript definitions for joi (Object schema description language and validator for JavaScript objects) https://joi.dev/

Getting started

Install joi and types-joi:

npm i joi types-joi

Use it:

import * as joi from "types-joi";
import { InterfaceFrom } from "types-joi";

const messageSchema = joi.object({
    status: joi.number().required(),
    body: joi.string()
}).required();

type Message = InterfaceFrom<typeof messageSchema>;

function processMessage(message: Message) {
    if (message.body) message.body.length;
}

const validatedMessage = joi.attempt({ some: "value" }, messageSchema);

processMessage(validatedMessage);

About

TypeScript types for joi (Object schema description language and validator for JavaScript objects) https://github.com/hapijs/joi


Languages

Language:TypeScript 98.4%Language:JavaScript 1.6%