question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scalar JSON always undefined due to default config of JSON set to type never

See original GitHub issue

Hi,

in DEFAULT_SHARED_CONFIG scalar JSON is set to never and this is creating an issue for the generated type gatsbyImageData when using it with gatsby-source-contentful. Tried changing JSON type to any and that seems to fix it.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kijecommented, Apr 29, 2021

@dgattey @cometkim beware Record<string, any> might not improve things/not work for the gatsbyImage use case, as helper functions from gatsby-plugin-image (like getImage) expect to get a ImageDataLike type passed as argument.

JSON: any would work without the need for a cast in this case, as all types can be casted to any (and vice versa). JSON: Record<string, any> on the other hand is not structurally equal to ImageDataLike and it cannot be casted to any type, thus Typescript will throw a type error since Record<string, any> is not guaranteed to have the required fields from ImageDataLike

Also, regardless of the gatsby image use case, something like [1,2,3] would also be valid JSON, so in this case Record<string, any> wouldn’t be the correct type either.

Thus, IMHO JSON: any seems to be IMHO the better type to use

2reactions
cometkimcommented, Mar 5, 2021

Hi @mhretab Thanks for the reporting.

I quit my job 3 months ago and haven’t had a chance to explore the new Gatsby APIs. However, I think I have had enough rest. I will try again soon and this will definitely be included in v3.

And please share your work if it is public. It will be very helpful for investigation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is "not assignable to parameter of type never" error in ...
Disclaimer: This is just a workaround. This error appears only when the null checks are not handled properly which in any case is...
Read more >
Define type of content of Json field · Issue #3219 - GitHub
Problem Right now if you have the following schema with Json field: model User { id Int @default(autoincrement()) @id name String?
Read more >
Documentation - Everyday Types - TypeScript
In this chapter, we'll cover some of the most common types of values you'll find in JavaScript code, and explain the corresponding ways...
Read more >
Resolvers - Apollo GraphQL Docs
We want to define resolvers for the numberSix and numberSeven fields of the root Query type so that they always return 6 and...
Read more >
Solve common issues with JSON in SQL Server
Question. I want to create a JSON text result from a simple SQL query on a single table. FOR JSON PATH and FOR...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found