-
-
Notifications
You must be signed in to change notification settings - Fork 544
Enhancement: readonly arrays #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Interesting! This makes sense to me. Just for clarification: should all arrays be |
Yes, that'd be my preference. 🙂 But it would depend on the codebase, and
whether it generally uses immutable data. Some apps might want to add items
to an array while building a response, or "pop" items from an input array
(e.g. if it's an intermediate proxy), particularly if performance is a
concern.
Maybe it should be configurable, via CLI option etc.
…On Thu, 4 Mar. 2021, 2:04 pm Drew Powers, ***@***.***> wrote:
Interesting! This makes sense to me.
Just for clarification: should *all* arrays be Readonly in TS generation?
My gut instinct would be yes, but I’d like to confirm that’s what you’d
think.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#501 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABQK4MHG5IQG7DABVFPKVWDTB32EXANCNFSM4YSL4A4Q>
.
|
That’s a fair point. My initial assumption was to treat it as immutable, but now that you say that, I myself have used this library to generate new structures before sending to an API (e.g. a I like the idea of a CLI flag that just turns all arrays into |
I second this. it would be great if we could also make all types immutable, not only arrays. e.g. graphql-code-generator for typescript has an option to generate immutable types: https://graphql-code-generator.com/docs/plugins/typescript
e.g.: type Foo {
readonly bar: readonly foobar[]
} |
It would be nice if we could use
ReadonlyArray
in place of[]
. Currently, trying to return aReadonlyArray
in a response will fail type checking, because the response requires a mutable array.e.g.
The text was updated successfully, but these errors were encountered: