Alt description missing in image
Beta: Plugins coming soon!
@app/coreschemasHealthCheckInput

HealthCheckInput

import { HealthCheckInput } from '@app/core/schemas/HealthCheckInput'

Location

        • HealthCheckInput.ts

Zod Schema

What the schema would look like when defined with z.object() in Zod V3:

const HealthCheckInput = z.object({
    echo: z
        .string()
        .default("Hello World")
        .describe("Echoed back the output argument"),
    verbose: z
        .boolean()
        .optional(),
})

(💡 Could be handy to copy-paste this schema info into an AI chat assistant)

Type Definition

You can extract the TypeScript type from the schema using z.input(), z.output() or z.infer() methods. e.g.:

type HealthCheckInput = z.input<typeof HealthCheckInput>

What the resulting TypeScript type would look like:

{
    /** Echoed back the output argument */
    echo?: string;
    verbose?: boolean;
}

(💡 Could be handy to copy-paste this type info into an AI chat assistant)

Usage - Validation

To validate data against this schema, you have a few options:

// Throws if invalid
const healthCheckInput = HealthCheckInput.parse(data)
 
// Returns { success: boolean, data?: T, error?: ZodError }
const healthCheckInput = HealthCheckInput.safeParse(data)
 

This might be useful for parsing API input data or validating form data before submission.

You can also directly integrate this schema with form state managers like our own:

Usage - Form State

import { useFormState } from '@green-stack/forms/useFormState'
 
const formState = useFormState(HealthCheckInput, {
    initialValues: { /* ... */ }, // Provide initial values?
    validateOnMount: true, // Validate on component mount?
})
 

Learn more about using schemas for form state in our Form Management Docs.

Usage - Component Props / Docs

Another potential use case for the ‘HealthCheckInput’ schema is to type component props, provide default values and generate documentation for that component:

export const HealthCheckInputComponentProps = HealthCheckInput.extend({
    // Add any additional props here
})
 
export type HealthCheckInputComponentProps = z.input<typeof HealthCheckInputComponentProps>
 
/* --- <HealthCheckInputComponent/> --------------- */
 
export const HealthCheckInputComponent = (rawProps: HealthCheckInputComponentProps) => {
 
    // Extract the props and apply defaults + infer resulting type
    const props = ComponentProps.applyDefaults(rawProps)
 
    // ... rest of the component logic ...
 
}
 
/* --- Documentation --------------- */
 
export const documentationProps = HealthCheckInputComponentProps.documentationProps('HealthCheckInputComponent')
 

Disclaimer - Automatic Docgen

🤖

These dynamic schema docs were auto-generated with npm run regenerate-docs. This happens automatically for schema files in any \schemas\ folder. You can opt-out of this by adding // export const optOut = true somewhere in the file.