Skip to content

Commit

Permalink
Fix TypeScript schema error when using project references (#1777)
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed Apr 30, 2024
1 parent 2616f0c commit 6949404
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .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
13 changes: 10 additions & 3 deletions packages/starlight/schema.ts
Expand Up @@ -117,7 +117,9 @@ type BaseSchemaWithoutEffects =
type BaseSchema = BaseSchemaWithoutEffects | z.ZodEffects<BaseSchemaWithoutEffects>;

/** Type that extends Starlight鈥檚 default schema with an optional, user-defined schema. */
type ExtendedSchema<T extends BaseSchema> = T extends BaseSchema
type ExtendedSchema<T extends BaseSchema | never = never> = [T] extends [never]
? DefaultSchema
: T extends BaseSchema
? z.ZodIntersection<DefaultSchema, T>
: DefaultSchema;

Expand Down Expand Up @@ -147,8 +149,13 @@ interface DocsSchemaOpts<T extends BaseSchema> {
}

/** Content collection schema for Starlight鈥檚 `docs` collection. */
export function docsSchema<T extends BaseSchema>({ extend }: DocsSchemaOpts<T> = {}) {
return (context: SchemaContext): ExtendedSchema<T> => {
export function docsSchema<T extends BaseSchema | never = never>(
...args: [DocsSchemaOpts<T>?]
): (context: SchemaContext) => ExtendedSchema<T> {
const [options = {}] = args;
const { extend } = options;

return (context: SchemaContext) => {
const UserSchema = typeof extend === 'function' ? extend(context) : extend;

return (
Expand Down

0 comments on commit 6949404

Please sign in to comment.