Skip to content

Commit 2e5e40a

Browse files
committed
Add zod schemas to author types
1 parent 48daade commit 2e5e40a

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

packages/web/docs/src/authors/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { StaticImageData } from 'next/image';
2+
import { z } from 'zod';
23
import saihajPhoto from './saihaj.webp';
34

45
export type Author =
@@ -18,6 +19,14 @@ export type Author =
1819
avatar?: string | StaticImageData;
1920
};
2021

22+
export const Author = z.object({
23+
name: z.string(),
24+
link: z.string().url(),
25+
twitter: z.string().optional(),
26+
github: z.string().optional(),
27+
avatar: z.union([z.string(), z.object({})]).optional(),
28+
});
29+
2130
export const authors = {
2231
kamil: {
2332
name: 'Kamil Kisiela',
@@ -253,3 +262,7 @@ export const authors = {
253262
} satisfies Record<string, Author>;
254263

255264
export type AuthorId = keyof typeof authors;
265+
266+
export const AuthorId = z.string().refine((val): val is AuthorId => val in authors, {
267+
message: `AuthorId must be one of: ${Object.keys(authors).join(', ')}`,
268+
});

pnpm-lock.yaml

Lines changed: 20 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)