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

"Property slug is not allowed" in VS Code #13107

Open
1 task
eikowagenknecht opened this issue Jan 31, 2025 · 2 comments
Open
1 task

"Property slug is not allowed" in VS Code #13107

eikowagenknecht opened this issue Jan 31, 2025 · 2 comments
Labels
- P2: has workaround Bug, but has workaround (priority) feat: typescript Related to TypeScript (scope)

Comments

@eikowagenknecht
Copy link

Astro Info

Astro                    v5.2.1
Node                     v22.12.0
System                   Windows (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/mdx
                         @astrojs/react
                         @astrojs/sitemap

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

No response

Describe the Bug

In VS code, I started to get a validation error "Property slug is not allowed." in all my markdown post files:

Image

The documentation here still mentions this, so I suppose it should work.

It seems only the fields defined in the collection schema are recognized:

Image

content.config.ts

import { defineCollection, z } from "astro:content";
import { glob } from "astro/loaders";

const posts = defineCollection({
  loader: glob({ pattern: "**/*.{md,mdx}", base: "./src/content/posts" }),
  schema: z.object({
    // Title of the post
    title: z.string(),
    // Date the post was published
    published: z.optional(z.date()),
    // Date the post was last updated
    updated: z.optional(z.date()),
    // A short description of the content
    description: z.string(),
    // An image to represent the post in previews
    // This results in image?: string | undefined, see https://github.com/colinhacks/zod/issues/635
    image: z.optional(z.string()),
    // A list of tags to categorize the post
    tags: z.array(z.string()),
  }),
});

export const collections = { posts };

This is a code editor problem only, setting the slug works just fine. It just would be nice to not have these errors appear in all markdown files.

What's the expected result?

slug should be recognized as a valid YAML metadata field.

Link to Minimal Reproducible Example

Not possible as the dev environment there accepts arbitrary YAML tags.

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 Jan 31, 2025
@ascorbic
Copy link
Contributor

It's not showing as a valid property because it's not in the schema. If you add it to the schema it will appear in the types and won't complain

@eikowagenknecht
Copy link
Author

I thought about doing so, but as it's a system property that is always available, shouldn't that be handled by Astro?

If the user needs to always add this, a hint in the above linked doc would be helpful.

@ascorbic ascorbic added - P2: has workaround Bug, but has workaround (priority) feat: typescript Related to TypeScript (scope) and removed needs triage Issue needs to be triaged labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) feat: typescript Related to TypeScript (scope)
Projects
None yet
Development

No branches or pull requests

2 participants