Skip to content

Unknown type error for nullable() and nullish() #1330

@dwidge

Description

@dwidge

problem

When we have a nullable() or nullish() zod field it throws 'unknown type'.

We can't use our main zod types for uniforms directly because we use null fields in the mysql database and endpoints. We use both types: undefined to mean unchanged or unknown, and null to mean the field is empty.

Maybe treat nullable the same as optional in the forms? Set the field to null if not entered by user?

workaround

Create separate zod types for uniforms with optional() instead of nullish() or nullable(). Replace undefined fields with null in the onSubmit handler. Keep them updated with the main schema.

packages

import ZodBridge from "uniforms-bridge-zod";
import { AutoForm } from "uniforms-mui";

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bridge: ZodAffects the uniforms-bridge-zod package

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Needs triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions