Navigation Menu

Skip to content

Commit

Permalink
fix(gatsby-plugin-image): Correct type for getImage (#36169)
Browse files Browse the repository at this point in the history
* update types

* allow null
  • Loading branch information
LekoArts committed Jul 19, 2022
1 parent 2805725 commit b3f434b
Showing 1 changed file with 6 additions and 3 deletions.
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>>
}

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

0 comments on commit b3f434b

Please sign in to comment.