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

Update MarkdownContent type #4028

Merged
merged 1 commit into from
Jul 28, 2022
Merged

Update MarkdownContent type #4028

merged 1 commit into from
Jul 28, 2022

Conversation

alfredogonzalezmartinez
Copy link
Contributor

@alfredogonzalezmartinez alfredogonzalezmartinez commented Jul 23, 2022

Changes

  • Add url and file properties to MarkdownContent type

Testing

N/A

Docs

Current docs indicates that MarkdownContent type should have properties url and file.

astro Docs - Markdown Layout (astro@1.0.0-beta.73)

'url' and 'file' properties were missing in MarkdownContent type,
but they should there according to:
https://docs.astro.build/en/guides/markdown-content/#markdown-layouts
@changeset-bot
Copy link

changeset-bot bot commented Jul 23, 2022

🦋 Changeset detected

Latest commit: 9340335

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

This PR includes changesets to release 12 packages
Name Type
astro Patch
@e2e/astro-component Patch
@e2e/error-react-spectrum Patch
@e2e/error-sass Patch
@e2e/errors Patch
@e2e/lit-component Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/svelte-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution Patch

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 Jul 23, 2022
@natemoo-re
Copy link
Member

Hi @alfredogonzalezmartinez! Thanks for the PR! Can you share where you're running into this types issue? I think file and url are only available on the MarkdownInstance but may not be passed through to MarkdownContent?

file: string;
url: string | undefined;

@alfredogonzalezmartinez
Copy link
Contributor Author

alfredogonzalezmartinez commented Jul 23, 2022

Hi @natemoo-re, when I want to assign a type to content prop in a layout for markdown files, I think that I should use MarkdownContent because its description says: "The content prop given to a Layout".

/**
 * The `content` prop given to a Layout
 *
 * [Astro reference](https://docs.astro.build/en/guides/markdown-content/#markdown-layouts)
 */
export declare type MarkdownContent<T extends Record<string, any> = Record<string, any>> = T & {
    astro: MarkdownMetadata;
};

But the content prop includes url and file properties that are not defined in MarkdownContent type and I get the next errors in my code editor:

  • Property 'url' does not exist on type 'MarkdownContent'.ts(2339)
  • Property 'file' does not exist on type 'MarkdownContent'.ts(2339)
---
import { MarkdownContent } from "astro";

interface Frontmatter {
  title: string;
}

const content:MarkdownContent<Frontmatter> = Astro.props.content

const {
  title,
  astro,
  url, // Property 'url' does not exist on type 'MarkdownContent<Frontmatter>'.ts(2339)
  file // Property 'file' does not exist on type 'MarkdownContent<Frontmatter>'.ts(2339)
} = content
---

Example of content prop output

In the release astro@1.0.0-beta.73, the PR #3588 adds url and file properties to content prop in markdown layouts.

astro MarkdownContent example

@matthewp
Copy link
Contributor

Makes sense, thanks!

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