microsoft / microsoft/TypeScript

[Post-7.0] Improve readability of `Array.from` / `TypedArray.from` `mapFn` parameters

Open Beginner friendly
#63,832 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Possible Improvement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.