From b3f434b38b9a5cbcbfb6d4afca260b39cdeb76a4 Mon Sep 17 00:00:00 2001 From: Lennart Date: Tue, 19 Jul 2022 13:43:14 +0200 Subject: [PATCH] fix(gatsby-plugin-image): Correct type for getImage (#36169) * update types * allow null --- packages/gatsby-plugin-image/src/components/hooks.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-plugin-image/src/components/hooks.ts b/packages/gatsby-plugin-image/src/components/hooks.ts index ce2bd9c5f99fd..038823ce15f97 100644 --- a/packages/gatsby-plugin-image/src/components/hooks.ts +++ b/packages/gatsby-plugin-image/src/components/hooks.ts @@ -27,8 +27,8 @@ export type IGatsbyImageDataParent = T & { export type IGatsbyImageParent = T & { gatsbyImage: IGatsbyImageData } -export type FileNode = Node & { - childImageSharp?: IGatsbyImageDataParent +export type FileNode = Partial & { + childImageSharp?: IGatsbyImageDataParent> } const isGatsbyImageData = ( @@ -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 }