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

Add astro/types for common prop patterns #5147

Merged
merged 8 commits into from
Oct 26, 2022
Merged

Add astro/types for common prop patterns #5147

merged 8 commits into from
Oct 26, 2022

Conversation

natemoo-re
Copy link
Member

@natemoo-re natemoo-re commented Oct 21, 2022

Changes

  • We have some common patterns that folks ask about, so this adds an astro/types entrypoint with some helpful utility types.
  • This keeps folks from needing to access the astroHTML.JSX.AnchorHTMLAttributes stuff directly
  • Based on docs section TypeScript: Common Prop Type Patterns

HTMLAttributes

If you would like to extend valid HTML attributes for a given HTML element, you may use the provided HTMLAttributes type—it accepts an element name and returns the valid HTML attributes for that element name.

import { HTMLAttributes } from 'astro/types';
interface Props extends HTMLAttributes<'a'> {
  myProp?: string;
};

Testing

Tested manually

Docs

withastro/docs#1857

@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2022

🦋 Changeset detected

Latest commit: ce62ad0

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

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 pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release labels Oct 21, 2022
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

Copy link
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking comment about the shape of things, but otherwise this is absolutely wonderful and everything I have ever wished for, awesome work!

Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a few thoughts on naming and documentation. But HTMLAttributes feels fundelemental to good Astro components 👏

.changeset/dirty-cycles-lick.md Outdated Show resolved Hide resolved
.changeset/dirty-cycles-lick.md Outdated Show resolved Hide resolved
@natemoo-re natemoo-re changed the title Add astro/type-utils for common prop patterns Add astro/types for common prop patterns Oct 21, 2022
Copy link
Contributor

@tony-sull tony-sull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is excellent! Will be able to clean up the @astrojs/image components too, they're doing a bit of a dance to add typings when extending <img> and <picture>

Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my type of change!

@natemoo-re natemoo-re merged commit 0bf0758 into main Oct 26, 2022
@natemoo-re natemoo-re deleted the feat/type-utils branch October 26, 2022 15:14
@astrobot-houston astrobot-houston mentioned this pull request Oct 26, 2022
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) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants