Feature request: graphqlTypegen should generate undefined properties of Queries, not null #37662
Unanswered
corgrath
asked this question in
Ideas / Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
With
graphqlTypegen
enabled, Gatsby generatesQueries
ingatsby-types.d.ts
.Here is an example of a generated query definition:
In Gatsby's own example on their documentation page:
https://www.gatsbyjs.com/docs/how-to/local-development/graphql-typegen/
They give the example of use:
<p>Site title: {data.site?.siteMetadata?.title}</p>
However, if you were to pass
title
into a function while using strict TypeScript check, you need to check for bothundefined
andnull
.This is because optional
object?.property
returnsundefined
why Gatsby's definition usesnull
.Meaning, if you use strict type checking, your code will easily be bloated with code such as:
And
It would make developer's life a lot easier if the type definitions were
undefined
instead ofnull
.Beta Was this translation helpful? Give feedback.
All reactions