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

Fixes type definitions @astrojs/image and adds more documentation to the README #4045

Merged
merged 22 commits into from
Jul 27, 2022

Conversation

tony-sull
Copy link
Contributor

@tony-sull tony-sull commented Jul 25, 2022

Changes

  • moves to a static types.d.ts for integration typings
  • exposes the getImage() and getPicture() helpers publicly
  • adds documentation for <Image /> and <Picture /> component properties
  • adds documentation for getImage() and getPicture()
  • finally found the magic balancing act to get proper typing for ESM imports!

ESM Import Types 🪄

Screen Shot 2022-07-26 at 4 45 44 PM

<Image /> component prop errors

Screen Shot 2022-07-26 at 4 46 56 PM

Component prop auto-complete

Screen Shot 2022-07-26 at 4 47 16 PM

Testing

All existing tests should pass

Docs

integration README updated

@changeset-bot
Copy link

changeset-bot bot commented Jul 25, 2022

🦋 Changeset detected

Latest commit: 01d18e0

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

This PR includes changesets to release 13 packages
Name Type
astro Patch
@astrojs/image Minor
@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: integration Related to any renderer integration (scope) label Jul 25, 2022
@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 26, 2022

// Built-in asset types
// see `src/constants.ts`
/// <reference path="./client-base.d.ts" />

// images
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Image types are still included here, using types: ["astro/client"] will get all types from client-base.d.ts plus basic image types

/// <reference types="vite/types/importMeta" />

// CSS modules
type CSSModuleClasses = { readonly [key: string]: string };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the real magic sauce for ESM import types

Moving out all the types except images into a client-base.d.ts allows the main use case of astro/client to work. The image integration now uses only this base file, avoiding the issue of duplicating *.jpg module definitions


export default integration;
export { getImage } from './lib/get-image.js';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out moving the actual integration out of index.ts was sometimes confusing the editor when working with astro.config.mjs files

@tony-sull tony-sull marked this pull request as ready for review July 26, 2022 22:09
@tony-sull tony-sull changed the title WIP: Fixes type definitions @astrojs/image and adds more documentation to the README Fixes type definitions @astrojs/image and adds more documentation to the README Jul 26, 2022
@tony-sull tony-sull self-assigned this Jul 26, 2022
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.

A few comments there and there, but nothing blocking. LGTM!

Ultimately, if astro add gets the possiblity of doing tsconfig changes, it'd be cool if it added the types for you as I can see users missing this step fairly easily.

Thank you for improving the editor experience 🥰

packages/integrations/image/README.md Outdated Show resolved Hide resolved
Copy link

@Fidge123 Fidge123 left a comment

Choose a reason for hiding this comment

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

I had one issue following this guide, but this may be due to me doing something wrong (see below).

Also I had one more idea, what I would like to see: The responsive image section should point out how to use this to support higher resolution screens (retina) which look better with 2x/3x scaling.

Comment on lines +246 to +251
```astro
---
import { getImage } from '@astrojs/image';

const { src } = await getImage('../assets/hero.png');
---

Choose a reason for hiding this comment

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

This does not work for me. Maybe I configured something incorrectly, but I tried to follow the README as it was stated here. Any idea why this happens? (same for getPicture)

'getImage' is not exported by node_modules/@astrojs/image/components/index.ts, imported by src/components/Picture.astro
file: /Users/fidge123/dev/private/project/src/components/Picture.astro:1:3
1: ---
      ^
2: import { getImage } from '@astrojs/image';
 error   'getImage' is not exported by node_modules/@astrojs/image/components/index.ts, imported by src/components/Picture.astro
  File:
    /Users/fidge123/dev/private/project/src/components/Picture.astro
  Code:
    1: ---
          ^
    2: import { getImage } from '@astrojs/image';

error Command failed with exit code 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getImage and getPicture aren't currently public, this PR will make them available in the next release 👍

The responsive image section should point out how to use this to support higher resolution screens (retina) which look better with 2x/3x scaling.

Definitely agree we can build up some really nice content for best practices here! I've actually been leaning towards writing a few blog posts that dives deeper into responsive images and how to use these components, the README could link to those for full details

Choose a reason for hiding this comment

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

Thank you for the clarification! I'm looking forward to those blog posts 😊

@tony-sull tony-sull merged commit a397b98 into main Jul 27, 2022
@tony-sull tony-sull deleted the fix/image-types branch July 27, 2022 15:39
@astrobot-houston astrobot-houston mentioned this pull request Jul 27, 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) pkg: integration Related to any renderer integration (scope)
Projects
None yet
5 participants