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

fix(gatsby-plugin-image): Correct type for getImage #36169

Merged
merged 2 commits into from Jul 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/gatsby-plugin-image/src/components/hooks.ts
Expand Up @@ -27,8 +27,8 @@ export type IGatsbyImageDataParent<T = never> = T & {
export type IGatsbyImageParent<T = never> = T & {
gatsbyImage: IGatsbyImageData
}
export type FileNode = Node & {
childImageSharp?: IGatsbyImageDataParent<Node>
export type FileNode = Partial<Node> & {
childImageSharp?: IGatsbyImageDataParent<Partial<Node>>
Comment on lines -30 to +31
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like we don't care about this looking like a "Node" properties at all and just care about childImageSharp? maybe we drop Node completely and have just have object type with childImageSharp optional field?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker tho, so will approve

}

const isGatsbyImageData = (
Expand All @@ -54,7 +54,10 @@ export type ImageDataLike =
| IGatsbyImageParent
| IGatsbyImageData

export const getImage = (node: ImageDataLike): IGatsbyImageData | undefined => {
export const getImage = (
node: ImageDataLike | null
): IGatsbyImageData | undefined => {
// This checks both for gatsbyImageData and gatsbyImage
if (isGatsbyImageData(node)) {
return node
}
Expand Down