Declaring prop with type `[String!]!` makes it also appear as `String` (possible bug?)
See original GitHub issueI 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
Checking my mutation
to confirm that I only have it as type [String!]!
A useState
where the error could be coming from but I’m also declaring it as ['']
The autogenerated variables for my mutation
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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! 🤘
@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 setarrayInputCoercion
to false in yourcodegen.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 theimages
variable. Setting thearrayInputCoercion
to false will stopgraphql-code-generator
from adding| Types.Scalars['String']
to your mutation variable types.