📦
Schema
  • Getting Started
  • Documents
    • Basics
      • Extend
    • Any
      • Label
      • Default
      • Required
      • Pipe
      • Validate
    • Array
      • Length
      • Max
      • Min
      • Items
    • Boolean
    • Date
      • Max
      • Min
    • Number
      • Max
      • Min
      • Multiple
      • Integer
      • Port
      • Positive
      • Precision
    • Object
      • Length
      • Max
      • Min
      • Keys
    • String
      • Alphanum
      • Credit Card
      • Email
      • Enum
      • IP Address
      • Length
      • Max
      • Min
      • Numeral
      • Regex
      • Token
  • Source Code
Powered by GitBook
On this page

Was this helpful?

  1. Documents
  2. Basics

Extend

Add new Schema types using the extend method

import Schema, { AnyType } from "@rapidom/schema";

class NewType extends AnyType<boolean> {
  protected initialValidator(value: unknown): boolean {
    if (typeof value === "boolean") return value;

    this.fail("Expected to be a boolean");
  }
}

const NewSchema = Schema.extend("name", () => new NewType());

NewSchema.name().validate();

This method will return the extended Schema and will not affect the original Schema

PreviousBasicsNextAny

Last updated 3 years ago

Was this helpful?