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

Refactor Props of Image and Picture component to support type checking #5788

Merged
merged 8 commits into from
Jan 18, 2023

Conversation

MoustaphaDev
Copy link
Member

@MoustaphaDev MoustaphaDev commented Jan 7, 2023

Changes

  • Refactor types to support props auto-completion for the Image and Picture components.
  • Pass previously missing alt prop to the getPicture function

Testing

Tested locally. There's only a small runtime change (see alt prop passed to the getPicture function). All tests should pass

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Jan 7, 2023

🦋 Changeset detected

Latest commit: c245aca

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 the pkg: integration Related to any renderer integration (scope) label Jan 7, 2023
@MoustaphaDev MoustaphaDev changed the title Refactor Props of Image and Picture component for better type checking Refactor Props of Image and Picture component to support type checking Jan 7, 2023

interface LocalImageProps
extends Omit<TransformOptions, 'src'>,
Copy link
Member Author

@MoustaphaDev MoustaphaDev Jan 7, 2023

Choose a reason for hiding this comment

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

For some reason, when generics are used directly inside the astro component, its props type become Record<string, any>. When extracted to another file, it works as expected

Copy link
Member

Choose a reason for hiding this comment

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

Our language server doesn't support generics at the moment, but it will soon. Your workaround seems valid, though!

cc @Princesseuh for a TS review 😄

@@ -59,6 +32,7 @@ const { image, sources } = await getPicture({
fit,
background,
position,
alt,
Copy link
Member Author

Choose a reason for hiding this comment

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

Ommiting alt was a mistake I guess?

@MoustaphaDev MoustaphaDev requested a review from tony-sull January 9, 2023 09:52
@delucis delucis requested a review from Princesseuh January 9, 2023 10:39
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for the PR!

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.

looks good to me!

This code actually was on par with other types back in the day, looks like it shows it's age now with all the improvements to the language server having much stronger support across the board


export interface ImageComponentLocalImageProps
extends Omit<TransformOptions, 'src'>,
Omit<ImgHTMLAttributes, 'src' | 'width' | 'height'> {
Copy link
Member

Choose a reason for hiding this comment

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

Should be astroHTML.JSX.ImgHTMLAttributes too?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe HTMLAttributes<'img'> from astro/types?

Copy link
Member Author

@MoustaphaDev MoustaphaDev Jan 9, 2023

Choose a reason for hiding this comment

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

Maybe HTMLAttributes<'img'> from astro/types?

Sounds good to me!

Copy link
Member Author

@MoustaphaDev MoustaphaDev Jan 9, 2023

Choose a reason for hiding this comment

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

Should be astroHTML.JSX.ImgHTMLAttributes too?

Probably not? I don't think we want astro directives here

@Princesseuh
Copy link
Member

Left a few comments! Let me know if you'd rather I push this PR over the line myself, as you've done plenty work already!

@MoustaphaDev
Copy link
Member Author

MoustaphaDev commented Jan 12, 2023

Left a few comments! Let me know if you'd rather I push this PR over the line myself, as you've done plenty work already!

Thanks! Your suggestions where helpful enough, I just need approval now 🙂

@MoustaphaDev MoustaphaDev merged commit 006405d into withastro:main Jan 18, 2023
@MoustaphaDev MoustaphaDev deleted the add-exported-types branch January 18, 2023 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants