-
Notifications
You must be signed in to change notification settings - Fork 124
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
add array-map
for keeping tuple length when using .map
#136
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Sindre Bøyum <[email protected]>
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
): { [K in keyof this]: U }; | |
): { readonly [K in keyof this]: U }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @ahrjarrett what difference does this make? Could we test it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.map
with a tuple, the length is lost. This means you loose the guard against accessing an item out of bounds.With
array-map
enabled, this code will now error: