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.

Declaring prop with type `[String!]!` makes it also appear as `String` (possible bug?)

See original GitHub issue

I don’t know if this is a bug or not but I would like, if possible, some clarification on why I’m having this issue.

I have an images that has a type [String!]! but when I try to map it, it appears that it can be of type String. On my initialValues I also have it as an array so I’m not fully understanding where this String comes from. If I step into the autogenerated files I can see that the typing can actually be of type String but why does this happen?

Trying to map over images and seeing that it can be of type String Screenshot 2021-10-28 at 10 04 00

Checking my mutation to confirm that I only have it as type [String!]! Screenshot 2021-10-28 at 10 04 23

A useState where the error could be coming from but I’m also declaring it as [''] Screenshot 2021-10-28 at 10 05 23

The autogenerated variables for my mutation Screenshot 2021-10-28 at 10 07 37

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ItzaMicommented, Nov 10, 2021

@dylanwulf, thank you for the help. That made absolute sense!

@brainkim, as @dylanwulf pointed out, it seems like it’s something that is already mentioned on the docs so it probably won’t make much sense to create an issue for that. Anyway, thank you for the help! 🤘

2reactions
dylanwulfcommented, Oct 28, 2021

@ItzaMi You understood the question right, the thing I was looking for was the command (graphql-codegen). Your problem is with graphql-code-generator, which is a separate project from apollo-client. Sounds like you want to set arrayInputCoercion to false in your codegen.yml file. https://www.graphql-code-generator.com/docs/plugins/typescript-operations As described in the docs, this option defaults to true because the graphql spec allows both arrays and single primitive values for list inputs. Your server will probably accept either an array or a single string for the images variable. Setting the arrayInputCoercion to false will stop graphql-code-generator from adding | Types.Scalars['String'] to your mutation variable types.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing string literal as a single prop in Typescript + React
The reason why you seen that error message is because you forcefully telling the type of props is an string but actually it...
Read more >
Typechecking With PropTypes - React
In this example, we're using PropTypes.string . When an invalid value is provided for a prop, a warning will be shown in the...
Read more >
How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, React's internal mechanism for adding type checking to component props.
Read more >
Typing Component Props - React TypeScript Cheatsheets
Basic Prop Types Examples​. A list of TypeScript types you will likely use in a React+TypeScript app: type AppProps = { message: string;...
Read more >
How to Use PropTypes in React - freeCodeCamp
The most basic way we can check a prop's type is by checking if it falls under the category of primitive types in...
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