@crow281/ts-file-module-template
    Preparing search index...

    Function validatePoint3

    • Checks whether a given value is a valid instance of Point3 and matches its JSON Schema.

      Parameters

      • data: unknown

        Value we want to check to see if it matches Point3.

      Returns data is Point3

      true if data is confirmed to be a valid instance of type Point3, false otherwise.

      If result is false, you may check property validatePoint3#errors for an array of ErrorObjects to figure out whatever went wrong.

      This example shows you how you can verify that a value matches type Point3.

      //A function that can only operate on Point3.
      //Will print it to the console.
      function printObject(obj: Point3): void {
      console.log(obj);
      }

      //Some object we want to validate.
      const obj: unknown = {
      someProperty: 25
      };

      //If this object is a valid instance of Point3.
      if (validatePoint3(obj)) {
      //We can use it as the type.
      printObject(obj);
      }
    Index

    Properties

    Properties

    errors?: ErrorObject<string, Record<string, any>, unknown>[] | null

    If the validation function returns false, this property will be set to an array of ErrorObjects, explaining why validation failed.

    If your project contains package ajv, then this function will use AJV's interface for them. If not, it will use an internal and independant interface, StandaloneErrorObject, to define them. Note that there is no runtime difference between the two types.

    This example shows you how to fetch the resulting ErrorObject array if something goes wrong during validation.

    //Some object we want to validate.
    const obj: unknown = {
    someProperty: 25
    };

    //If this object is NOT a valid instance of Point3.
    if (!validatePoint3(obj)) {
    //Tell user validation failed.
    console.log("Obj is NOT an instance of Point3");

    //Fetch the list of errors.
    const errors = validatePoint3.errors;

    //By default, the error messages are in English.
    //Use ajv-i18n to localize the error messages.
    //This localize function was imported from "ajv-i18n/localize/fr"
    //and will translate the error messages to French.
    localize(errors);

    //Iterate the errors.
    for (const error of errors) {
    //Print the error representing whatever went wrong.
    console.log(error);
    }
    }