-
Notifications
You must be signed in to change notification settings - Fork 64
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
Upgrade to ReadOnlyArray (TS 2.0) #113
Comments
I respect the pure FP views here, though it'd make for a breaking change. Certainly, Ramda does not aim to aid in mutating objects. Technically though, its results though are still JS objects, and technically allow the user to mutate them otherwise as they wish. I'd compare this to the views at Ramda itself, which have been somewhat careful, relegating the 'breaking' pure-FP views to the likes of My inclination here would be to follow that example, and welcome this approach as a separate branch for those who appreciate the limitation it imposes. |
I just gave this a second thought. I realize just relegating this to a branch would be unfortunate in the sense it'd make for duplicate work on further edits, and I was thinking of a way we could potentially address this. I'd propose having a PR to add e.g. I realize it remains a compromise, but might this perhaps work out for your purposes @jonaskello? |
Yes, seems like a nice solution! For input parameters we could directly use ReadonlyArray since it will not be a breaking change (because of structural typing you can pass regular Array to ReadonlyArray). But for output arrays as you notice, it would be a breaking change. So having a type alias OutputArray like you propose is a nice compromise to keep it non-breaking and easy to change to fully immutable. I'll post a PR with these changes. |
Sounds good. Thanks! :) |
Related: given the request for ImmutableJS support, I wonder if for arrays in input params we should perhaps just use |
I think using |
I'm currently handling the input parameters for that, testing on a
case-by-case basis with Ramda. It appears Iterable isn't actually supported
for most functions, while ArrayLike (handles Array, ReadOnlyArray, string)
appears fine. I was currently adding in ArrayLike there, but using that
through a variable would work for me as well. Output ones I haven't touched.
…On Fri, Dec 9, 2016 at 4:45 PM, Jonas Kello ***@***.***> wrote:
I think using Iterable would require some more consideration than I am
currently doing. For example adding more tests. So I think it might be
better to do it in two steps. I could make InputArray a type alias too like type
InputArray<T> = Array<T> and later we could easily change to type
InputArray<T> = Iterable<T>. Or you can do a text search for InputArray
and change it directly to Iterable if that is desired. As it is right now
everything is declared as T[] and I am going through them and classifying
as Input or Output.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#113 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC6uxceTi23bRB2voI-QYdOL2wsN_F_Mks5rGRUTgaJpZM4K9tNW>
.
|
I just pushed a switch to |
I tried to merge my fork but got conflicts on every line :-). It seems like all input arrays are changed to |
Ok, so I think I see now where you are going with this. This is the definition of
And you are saying that you have checked all functions in Ramda and the only thing they ever do is check length or query by index? In that case this is a nice solution because it would cover |
Sorry about that On On that topic, I might want to inquire how branches might work at DefinitelyTyped... |
No problem :-). I actually think I don't need to add anything to your edits for ReadonlyArray to work as input now that ArrayLike is in place. So I guess we could just close this? Btw my use-case for ReadonlyArray is that I want to use these tslint rules instead of ImmutableJS or seamless-immutable. |
IIRC it is not possible to create your own indexers in JS, it is only regular objects or arrays that are indexable with the [] operator. So I think ImmutableJS it uses special .get and .set methods which would make them incompatible with ArrayLike. But that is not important for this issue :-). |
Okay, if you turn out to need more let's reopen then. :) On Immutable, we just had another thread as well, but yeah, I definitely feel Ramda is being a bit old-fashioned there by doing loops instead of hooking into the Then again, it might raise questions on whether in that case return types should use |
Correction: seems they do plan on doing iterators. |
Is this issue resolved? How can i use |
Hm. Sounds weird, |
@tycho01 the types for ramda is installed using BTW With this version, is this suppose to work?
I still get this error:
|
@rajdeep26: thanks for that. Would you mind trying |
In TypeScript 2.0 we have ReadOnlyArray which I think is a perfact match for a library like ramda that does not do any mutations.
Would it be OK if I did a PR that changes to ReadOnlyArray?
Here is a short example how it works:
The text was updated successfully, but these errors were encountered: