Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions fools/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ export const UserSchema = z.object({
// ✅ TypeScript inference
export type User = z.infer<typeof UserSchemassss>ssssss

// ✅ Safe parsing with v4 error helpers
/**
* Validate a value against the UserSchema and return the validated User.
*
* @param input - The value to validate as a User
* @returns The validated `User` object
* @throws Error containing the JSON-stringified v4 validation error tree when validation fails
*/
export function parseUser(input: unknown): User {
const result = UserSchema.safeParse(input)
if (!result.success) {
throw new Error(JSON.stringify(result.error.treeify())) // v4 structured error
}
return result.data
}