Repository navigation
Array callbacks take the element's index too - #59
Merged
Merged
Conversation
`xs.map((x, i) => x + i)` was "can't assign '(p0, p1) => ...' to '(p0) => ...'": every array callback took the element only. map, filter, filter2, find, findIndex, findLast, findLastIndex, forEach, some and every (and the Array<T> class's forwards) now take `(v: T, i: number)`, as JavaScript gives them; a callback taking the element only is given through the compiler's fewer-parameters thunk. Needs TypeScriptCompiler#738 (inference and own fixes for that thunk). Test: tests/array_callback_index.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Array callbacks now take the element's index. For example,
xs.map((x, i) => x + i).map,filter,filter2,find,findIndex,findLast,findLastIndex,forEach,someandevery(and theArray<T>class's forwarding methods) now take(v: T, i: number), as JavaScript passes them.Merge after ASDAlexander77/TypeScriptCompiler#738. Without its fixes, a capturing callback for a generic method infers the wrong
T, and own rejects a string returned through the wrapper.Test:
tests/array_callback_index.ts. Validation, with #738's compiler, release JIT: gc 182/182, rc and none 181 (1 skipped), own 171 (11 skipped), plus the declarations check.🤖 Generated with Claude Code