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

Document using / extending the Astro JSX definitions #984

Closed
Princesseuh opened this issue Jul 14, 2022 · 2 comments · Fixed by #1005
Closed

Document using / extending the Astro JSX definitions #984

Princesseuh opened this issue Jul 14, 2022 · 2 comments · Fixed by #1005
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages.

Comments

@Princesseuh
Copy link
Member

Princesseuh commented Jul 14, 2022

This is very advanced usage, nonetheless we see some people do it. Notably, our official image integration use them to provide img props completions and type checking in the components

Using them is done through a triple slash directive, this works both in Astro files and in TypeScript files

---
/// <reference types="astro/astro-jsx" />

// Access them directly:
export type Props = astroHTML.JSX.ImgHTMLAttributes;
---

<img ...>

Extending them is done through a .d.ts file redeclaring the namespace:

declare namespace astroHTML.JSX {
  interface HTMLAttributes {
    mycustomattribute?: any;
  }
}

People tend to extend them whenever they want non-standard attributes while still having typechecking. Another case is when we made a mistake and some attributes isn't included in our definitions 😅

@delucis
Copy link
Member

delucis commented Jul 14, 2022

Maybe we can add this to our Typescript page? Are there other use cases for triple-slash directives augmenting ambient types we would want to mention and does it matter where .d.ts are?

@delucis delucis added the add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. label Jul 14, 2022
@Princesseuh
Copy link
Member Author

Maybe we can add this to our Typescript page? Are there other use cases for triple-slash directives augmenting ambient types we would want to mention and does it matter where .d.ts are?

I do not think there's other use cases specific to Astro and it shouldn't matter where the .d.ts is in this case, though I have heard of issues when using a folder called "types" in the past

delucis added a commit that referenced this issue Jul 15, 2022
delucis added a commit that referenced this issue Jul 15, 2022
* Document use of Astro’s JSX types

Closes #984

* Use new element-specific interface

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>

* Add note about `astroHTML` in `.ts` files

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants