You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Type '{ children: any; title: string; }' is not assignable to type 'IntrinsicAttributes & Props'.
Property 'title' does not exist on type 'IntrinsicAttributes & Props'.
🖥️ Reproduction in StackBlitz (if reporting incorrect content or code samples)
No response
The text was updated successfully, but these errors were encountered:
When dealing with Astro.props.frontmatter, default Props can't be overridden, I can't find the documentation for that specifically (maybe a docs PR needed? question to Sarah). A custom prop interface is required in that case:
---typeCustomProps={title: string};const{ title }: CustomProps=Astro.props.frontmatter||Astro.props;---<html><head></head><body><h1>{title}</h1><slot/></body></html>
Linking a gist for consecutive code snippets shared in this issue - Docs Issue 8692.
Thanks for this @at-the-vr ! Since the HTML template part is the same in both examples, I'm wondering whether we can get away with showing just the script part here as the version to use if you're writing TypeScript?
As for the default Props types can't be overridden, maybe there's a place in the TypeScript guide itself to mention that?
📚 Subject area/topic
Using one Layout for .md, .mdx, and .astro
📋 Page(s) affected (or suggested, for new content)
https://docs.astro.build/en/basics/layouts/#using-one-layout-for-md-mdx-and-astro
📋 Description of content that is out-of-date or incorrect
The article linked above gives the following example of an Astro layout file that accepts both JSX props and frontmatter props:
But it's unclear how this can be used together with TypeScript to get typesafety.
If I just do this, then TypeScript complains that
frontmatter
does not exist onAstro.props
:So then I tried this, but that doesn't work either:
TypeScript still complains that
Astro.props.frontmatter
does not exist:Finally, I also tried:
But then the JSX usage gives a different error:
src/pages/index.astro
🖥️ Reproduction in StackBlitz (if reporting incorrect content or code samples)
No response
The text was updated successfully, but these errors were encountered: