Skip to content

Commit

Permalink
Move astro:content types declaration to manual ambient module (#10013)
Browse files Browse the repository at this point in the history
* Move `astro:content` types declaration to manual ambient module

* Add changeset

---------

Co-authored-by: bluwy <[email protected]>
  • Loading branch information
delucis and bluwy authored Feb 7, 2024
1 parent b07a384 commit e6b5306
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 80 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-ravens-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fixes a regression in content collection types
5 changes: 1 addition & 4 deletions packages/astro/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference types="vite/types/import-meta.d.ts" />
/// <reference path="./types/content.d.ts" />

// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace App {
Expand Down Expand Up @@ -160,10 +161,6 @@ declare module 'astro:components' {
export * from 'astro/components';
}

declare module 'astro:content' {
export * from 'astro/virtual-modules/content.js';
}

type MD = import('./dist/@types/astro.js').MarkdownInstance<Record<string, any>>;
interface ExportedMarkdownModuleEntities {
frontmatter: MD['frontmatter'];
Expand Down
76 changes: 0 additions & 76 deletions packages/astro/src/virtual-modules/content.ts

This file was deleted.

75 changes: 75 additions & 0 deletions packages/astro/types/content.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
declare module 'astro:content' {
export { z } from 'astro/zod';

// This needs to be in sync with ImageMetadata
export type ImageFunction = () => import('astro/zod').ZodObject<{
src: import('astro/zod').ZodString;
width: import('astro/zod').ZodNumber;
height: import('astro/zod').ZodNumber;
format: import('astro/zod').ZodUnion<
[
import('astro/zod').ZodLiteral<'png'>,
import('astro/zod').ZodLiteral<'jpg'>,
import('astro/zod').ZodLiteral<'jpeg'>,
import('astro/zod').ZodLiteral<'tiff'>,
import('astro/zod').ZodLiteral<'webp'>,
import('astro/zod').ZodLiteral<'gif'>,
import('astro/zod').ZodLiteral<'svg'>,
import('astro/zod').ZodLiteral<'avif'>,
]
>;
}>;

type BaseSchemaWithoutEffects =
| import('astro/zod').AnyZodObject
| import('astro/zod').ZodUnion<[BaseSchemaWithoutEffects, ...BaseSchemaWithoutEffects[]]>
| import('astro/zod').ZodDiscriminatedUnion<string, import('astro/zod').AnyZodObject[]>
| import('astro/zod').ZodIntersection<BaseSchemaWithoutEffects, BaseSchemaWithoutEffects>;

type BaseSchema =
| BaseSchemaWithoutEffects
| import('astro/zod').ZodEffects<BaseSchemaWithoutEffects>;

export type SchemaContext = { image: ImageFunction };

type DataCollectionConfig<S extends BaseSchema> = {
type: 'data';
schema?: S | ((context: SchemaContext) => S);
};

type ContentCollectionConfig<S extends BaseSchema> = {
type?: 'content';
schema?: S | ((context: SchemaContext) => S);
};

type CollectionConfig<S extends BaseSchema> =
| ContentCollectionConfig<S>
| DataCollectionConfig<S>;

export function defineCollection<S extends BaseSchema>(
input: CollectionConfig<S>
): CollectionConfig<S>;

/** Run `astro sync` to generate high fidelity types */
export const getEntryBySlug: (...args: any[]) => any;
/** Run `astro sync` to generate high fidelity types */
export const getDataEntryById: (...args: any[]) => any;
/** Run `astro sync` to generate high fidelity types */
export const getCollection: (...args: any[]) => any;
/** Run `astro sync` to generate high fidelity types */
export const getEntry: (...args: any[]) => any;
/** Run `astro sync` to generate high fidelity types */
export const getEntries: (...args: any[]) => any;
/** Run `astro sync` to generate high fidelity types */
export const reference: (...args: any[]) => any;
/** Run `astro sync` to generate high fidelity types */
export type CollectionKey = any;
/** Run `astro sync` to generate high fidelity types */
export type CollectionEntry<C> = any;
/** Run `astro sync` to generate high fidelity types */
export type ContentCollectionKey = any;
/** Run `astro sync` to generate high fidelity types */
export type DataCollectionKey = any;
/** Run `astro sync` to generate high fidelity types */
export type ContentConfig = any;
}

0 comments on commit e6b5306

Please sign in to comment.