Libraries
    Preparing search index...
    • Creates a schema that validates the value is exactly null.

      By default the schema is required — only null is accepted. Call .optional() to also allow undefined.

      Returns NullSchemaBuilder<true, false, undefined, false, {}>

      import { nul } from '@cleverbrush/schema';

      nul().validate(null); // { valid: true, object: null }
      nul().validate(undefined); // { valid: false }
      nul().validate(0); // { valid: false }
      nul().optional().validate(null);       // { valid: true, object: null }
      nul().optional().validate(undefined); // { valid: true, object: undefined }
      nul().optional().validate(false); // { valid: false }
      // Nullable field in an object schema
      import { object, string, nul, union, InferType } from '@cleverbrush/schema';

      const Schema = object({
      name: string(),
      deleted: union(nul()).or(string()), // null | string
      });

      type T = InferType<typeof Schema>;
      // { name: string; deleted: null | string }