diff --git a/.changeset/spotty-mice-travel.md b/.changeset/spotty-mice-travel.md new file mode 100644 index 00000000000..102f2e191a9 --- /dev/null +++ b/.changeset/spotty-mice-travel.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Fixes an issue where TypeScript could fail to serialize the frontmatter schema when configured to emit declaration files diff --git a/packages/starlight/schema.ts b/packages/starlight/schema.ts index a3534af055e..ad281e5c53d 100644 --- a/packages/starlight/schema.ts +++ b/packages/starlight/schema.ts @@ -117,7 +117,9 @@ type BaseSchemaWithoutEffects = type BaseSchema = BaseSchemaWithoutEffects | z.ZodEffects; /** Type that extends Starlight’s default schema with an optional, user-defined schema. */ -type ExtendedSchema = T extends BaseSchema +type ExtendedSchema = [T] extends [never] + ? DefaultSchema + : T extends BaseSchema ? z.ZodIntersection : DefaultSchema; @@ -147,8 +149,13 @@ interface DocsSchemaOpts { } /** Content collection schema for Starlight’s `docs` collection. */ -export function docsSchema({ extend }: DocsSchemaOpts = {}) { - return (context: SchemaContext): ExtendedSchema => { +export function docsSchema( + ...args: [DocsSchemaOpts?] +): (context: SchemaContext) => ExtendedSchema { + const [options = {}] = args; + const { extend } = options; + + return (context: SchemaContext) => { const UserSchema = typeof extend === 'function' ? extend(context) : extend; return (