add array-map for keeping tuple length when using .map - #136
Conversation
Co-authored-by: Sindre Bøyum <boyum@users.noreply.github.com>
shouldnt the |
|
Oops. Yep good spot thanks fixed now |
|
It was just me being pedantic. 🤗 |
| map<U>( | ||
| callbackfn: (value: T, index: number, array: readonly T[]) => U, | ||
| thisArg?: any, | ||
| ): { [K in keyof this]: U }; |
There was a problem hiding this comment.
| ): { [K in keyof this]: U }; | |
| ): { readonly [K in keyof this]: U }; |
There was a problem hiding this comment.
hey @ahrjarrett what difference does this make? Could we test it?
There was a problem hiding this comment.
In my mind, if this doesn't seem to make a difference, that only happens to be true for the set of inputs we've tried it with.
Fixing the output of a readonly array's map operation to be readonly seems like a reasonable thing to do. It creates a cohesive API, its semantics are unambiguous, and it eliminates the possibility that one of the property modifiers might change out from under us.
Probably a moot point anyway, since I don't know if this addition is in keeping with the design goals of ts-reset. That said, I'm personally all for preserving structure like this where possible, so I went ahead and made the suggestion :)
When you're using
Array.mapwith a tuple, the length is lost. This means you loose the guard against accessing an item out of bounds.With
array-mapenabled, this code will now error: