Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astro Content Collections vs. Assets Type Mismatch #8589

Closed
1 task
jlarmstrongiv opened this issue Sep 18, 2023 · 3 comments
Closed
1 task

Astro Content Collections vs. Assets Type Mismatch #8589

jlarmstrongiv opened this issue Sep 18, 2023 · 3 comments
Labels
needs triage Issue needs to be triaged

Comments

@jlarmstrongiv
Copy link

Astro Info

Astro                    v3.1.0
Node                     v18.17.1
System                   macOS (x64)
Package Manager          npm

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Type error:

Type 'ImageMetadata' is not assignable to type '{ src: string; width: number; height: number; format: "png" | "jpg" | "jpeg" | "tiff" | "webp" | "gif" | "svg"; }'.
  Types of property 'format' are incompatible.ts(2322)
config.ts(18, 7): The expected type comes from property 'heroImage' which is declared here on type 'IntrinsicAttributes & { updatedDate?: Date | undefined; title: string; description: string; pubDate: Date; heroImage: { src: string; width: number; height: number; format: "png" | ... 5 more ... | "svg"; }; }'

Astro asset types:

interface ImageMetadata {
    src: string;
    width: number;
    height: number;
    format: InputFormat;
}
type InputFormat = "avif" | "png" | "webp" | "jpeg" | "jpg" | "svg" | "tiff" | "gif"

Astro content types:

    // 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'>,
            ]
        >;
    }>;

What's the expected result?

No type errors.

Link to Minimal Reproducible Example

https://github.com/withastro/astro/files/12644675/astro-types-mismatch.zip

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Sep 18, 2023
@jlarmstrongiv
Copy link
Author

CC @TheOtterlord from Discord and @Princesseuh from #8518

@jlarmstrongiv
Copy link
Author

jlarmstrongiv commented Sep 18, 2023

For the reproduction:

  • downlod the zip
  • unzip to a folder
  • cd to the folder
  • run npm install
  • run astro dev
  • check out these pages
    • src/pages/about.astro
    • src/content/config.ts

@Princesseuh
Copy link
Member

Fixed by #8568

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants