From d26c03f5f31554239d1cb6d749447c8504b1dd01 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Tue, 19 Jul 2022 12:34:18 +0200 Subject: [PATCH 1/2] update types --- packages/gatsby-plugin-image/src/components/hooks.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-plugin-image/src/components/hooks.ts b/packages/gatsby-plugin-image/src/components/hooks.ts index ce2bd9c5f99fd..4b36e3e86092b 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 = ( @@ -55,6 +55,7 @@ export type ImageDataLike = | IGatsbyImageData export const getImage = (node: ImageDataLike): IGatsbyImageData | undefined => { + // This checks both for gatsbyImageData and gatsbyImage if (isGatsbyImageData(node)) { return node } From fe5793fefc6c5d0f1006bdee30a65c22ff69eba3 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Tue, 19 Jul 2022 12:41:04 +0200 Subject: [PATCH 2/2] allow null --- packages/gatsby-plugin-image/src/components/hooks.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-plugin-image/src/components/hooks.ts b/packages/gatsby-plugin-image/src/components/hooks.ts index 4b36e3e86092b..038823ce15f97 100644 --- a/packages/gatsby-plugin-image/src/components/hooks.ts +++ b/packages/gatsby-plugin-image/src/components/hooks.ts @@ -54,7 +54,9 @@ 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