microsoft / microsoft/TypeScript
[Post-7.0] Improve readability of `Array.from` / `TypedArray.from` `mapFn` parameters
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Currently, the `mapFn` argument of `Array.from()` is typed as `(v: T, k: number) => U`.
However, when this information is displayed in an IDE tooltip, it is difficult to grasp what values are passed to `v` and `k`.
To improve clarity, I propose changing the type definition to `(element: T, index: number) => U`, following [the description of the same method in MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from). The same applies to TypedArray.from().
Supplementary Information:
- The target file is `internal/bundled/libs/lib.es2015.iterable.d.ts#L107`.
- These changes are not intended to fix differences between 6.0 and 7.0, and according to `CONTRIBUTING.md`, the Pull Request should be submitted after the 7.0 release. I plan to submit a Pull Request for this once 7.0 is released.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at internal/bundled/libs/lib.es2015.iterable.d.ts#L107 and locate the Array.from and TypedArray.from mapFn declarations. Compare their parameter naming with the linked MDN description, then confirm both declarations use descriptive element and index names without changing their types or behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100