Skip to content
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

[feature] immutable data structures #78

Open
scottc opened this issue Jun 10, 2019 · 4 comments
Open

[feature] immutable data structures #78

scottc opened this issue Jun 10, 2019 · 4 comments

Comments

@scottc
Copy link

scottc commented Jun 10, 2019

Generated mutable types:

interface Thing {
  name: string;
  children: Array<Thing>; 
}

type x = ResponseWithBody<200, Array<Thing>>;

Could be immutable types:

interface ReadonlyThing {
  readonly name: string;
  readonly children: ReadonlyArray<Thing>; 
}

type x = ReadonlyResponseWithBody<200, ReadonlyArray<ReadonlyThing>>;

This would be a breaking change, so maybe mutable types by default and opt-in to immutable types, by configuration flag.

Although my personal preference would be immutable by default.

Reason being is that I'm using functional programming paradigm, where immutable data-structures are preferred, to avoid accidental state mutation as a safety feature.

@mtennoe
Copy link
Owner

mtennoe commented Jun 11, 2019

+1 on this! My expectation in my projects as well. I think to support backwardscompatibility we should make it an opt-in feature.

A bit of a side track - this brings up the good question on how we want to handle backwards compatibility overall. I.e. when do we want to say its ok to break something, and when do we want to keep backwards compatibility? I don't see a clear rule for this myself. @scottc, @Markionium - thoughts?

@scottc
Copy link
Author

scottc commented Jun 13, 2019

IMHO, hide it behind a config flag, to opt-in as an early adopter.

And later when there is a major release, change the defaults, to opt-in by default.
If there is consensus among the community.

Can have an open issue to gather community feedback and votes, for a period of time. Before making a final decision.

@mtennoe
Copy link
Owner

mtennoe commented Jun 13, 2019

Like it, sounds like a reasonable approach (and what many other projects do)

@Kosta-Github
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants