Skip to content

Commit 76b7c29

Browse files
committed
fix(content): type broken when augmenting
Fixes harlan-zw/nuxt-seo#450
1 parent ef042a2 commit 76b7c29

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/content.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@ import type { Collection } from '@nuxt/content'
22
import type { TypeOf, ZodRawShape } from 'zod'
33
import { z } from '@nuxt/content'
44

5+
export const ogImageSchema = z.object({
6+
url: z.string().optional(),
7+
component: z.string().optional(),
8+
props: z.record(z.string(), z.any()),
9+
}).optional()
10+
511
export const schema = z.object({
6-
ogImage: z.object({
7-
url: z.string().optional(),
8-
component: z.string().optional(),
9-
props: z.record(z.string(), z.any()),
10-
}).optional(),
12+
ogImage: ogImageSchema,
1113
})
1214

1315
export type OgImageSchema = TypeOf<typeof schema>
1416

15-
export function asOgImageCollection<T extends ZodRawShape>(collection: Collection<T>): Collection<T> {
17+
type ExtendedSchema<T extends ZodRawShape> = T & {
18+
ogImage: typeof ogImageSchema
19+
}
20+
21+
export function asOgImageCollection<T extends ZodRawShape>(collection: Collection<T>): Collection<ExtendedSchema<T>> {
1622
if (collection.type === 'page') {
1723
// @ts-expect-error untyped
1824
collection.schema = collection.schema ? schema.extend(collection.schema.shape) : schema
1925
}
20-
return collection
26+
return collection as Collection<ExtendedSchema<T>>
2127
}

0 commit comments

Comments
 (0)