-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
TS - Fix Gatsby image type #7702
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Gatsby Cloud Build Reportethereum-org-website-dev 🎉 Your build was successful! See the Deploy preview here. Build Details🕐 Build time: 16m |
@@ -89,15 +89,16 @@ const ActionCard: React.FC<IProps> = ({ | |||
isRight, | |||
isBottom = true, | |||
}) => { | |||
const isImageURL = typeof image === "string" && image.includes("http") | |||
const isImageURL = typeof image === "string" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplifying this condition. Any sort of string must be passed to an html img
tag.
isSvg = true | ||
} | ||
} | ||
const isImgSrc = typeof image === "string" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If image
is a string just pass it to the img
tag since GatsbyImage
can't process it anyway.
Furthermore, in all the instances where we are using ProductCard
, we are not sending a string. Only Gatsby image instances.
Implement correct types for Gatsby images.
The native
getImage
andgetSrc
Gatsby functions do not play very well with the types generated by GraphQL Typegen.The Gatsby team has improved a bit these functions but they still do not support null values.
In this PR, I've created a custom wrapper to deal with the null cases.
Most of the changes you see here are just:
getImage
andgetSrc
functionsstring
before. These are:ImageDataLike
=> data shape returned by the graphql queryIGatsbyImageData
=> data shape returned by thegetImage
function