Skip to main content

$ref

Callable

  • $ref<Reference>(reference: ConstExpr<Reference>, options?: SchemaOptions<object, Reference[infer]>): RefType<Intrinsic<Reference>>
  • $ref<T>(reference: T, options?: SchemaOptions<object>): ZodSchemaAsNode<T>
  • $ref<T>(reference: Schema<T>, options?: SchemaOptions<object>): SchemaAsNode<T>
  • $ref<T>(reference: T, options?: SchemaOptions<object>): Promise<RefType<NodeTrait & { infer: Infer<T> }>>

  • Create a new RefType instance with the given options.

    Example

    const foo = $number()
    $ref(foo)

    $ref(["foobar", foo])

    Type parameters

    Parameters

    • reference: ConstExpr<Reference>

      The schema to reference.

    • optionaloptions: SchemaOptions<object, Reference[infer]>

      Additional options to pass to the number.

    Returns RefType<Intrinsic<Reference>>