Skip to content

Type Alias: InferModelInput<M>

InferModelInput<M> = StandardSchemaV1.InferInput<M["schema"]>

Defined in: packages/model/src/types.ts:66

Infers the input type of a model created with createModel.

This represents the data structure that the model accepts before validation and transformation. It's also the value accepted by the from method.

The input type may differ from the output type when the schema includes transformations like trimming, parsing, or coercion.

Type Parameters

M

M extends object

Type of the model object containing a schema property

Example

typescript
import { createModel, InferModelInput, InferModelOutput } from '@uni-ts/model';
import { z } from 'zod';

const BlogPost = createModel(z.object({
  title: z.string().trim(),
  status: z.preprocess((value: string) => String(value), z.enum(['draft', 'published'])),
  publishedAt: z.date().transform((date) => date.toISOString()),
}));

// Infer input type - what the model accepts
type BlogPostInput = InferModelInput<typeof BlogPost>;
// { title: string; status: string; publishedAt: Date }

// Infer output type - what the model produces
type BlogPost = InferModelOutput<typeof BlogPost>;
// { title: string; status: 'draft' | 'published'; publishedAt: string }

function createBlogPost(input: BlogPostInput): BlogPost {
  return BlogPost.from(input); // validates and transforms input to output
}