Skip to content

Conversation

@ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Apr 28, 2025

Changes

Currently the way that BaseSchemaWithoutEffects is defined means that it's infinitely recursive, causing TypeScript to bail and type it as any. This means that there's no proper typechecking on content config schema, and was also making it hard to type live content loaders. This PR should fix that: it splits the composite types out. It no longer uses recursive types for allowed unions, but instead allows unions of non-unions, but also allows unions of any other unions. We don't check those deep unions anymore because wtf calm down stop being mean to TypeScript.

Testing

Tested both with the examples, but also the docs site and manually with various combinations.

Docs

@changeset-bot
Copy link

changeset-bot bot commented Apr 28, 2025

🦋 Changeset detected

Latest commit: 860d3f2

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Apr 28, 2025
@ascorbic ascorbic force-pushed the recursive-schema-types branch from b6c075f to 860d3f2 Compare April 28, 2025 11:15
@ascorbic ascorbic marked this pull request as ready for review April 28, 2025 11:18
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly didn't understand what we're fixing. Can you share some screenshot or something, since we can't create a test?

@ascorbic
Copy link
Contributor Author

The fix is that previously the recursive type meant that the type-checker gave up and typed BaseSchema as any. This in turn meant that when using defineCollection to define the content config, the schema field was also typed as any, so there was no type-checking for it:
image

This PR gets rid of the recursion. The price is that it no longer attempts to type-check unions of unions, but as previously it wasn't type-checking anything, that's not a loss!

@ascorbic
Copy link
Contributor Author

...and now:
image

@ascorbic ascorbic merged commit b4929ae into main Apr 28, 2025
14 checks passed
@ascorbic ascorbic deleted the recursive-schema-types branch April 28, 2025 12:12
@astrobot-houston astrobot-houston mentioned this pull request Apr 28, 2025
openscript pushed a commit to openscript/astro that referenced this pull request Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants