[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.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
tooling

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.

Description

Possible Improvement

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. 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.
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 15h
Merged PRs (30d)
106

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.

More from microsoft/TypeScript

All issues in microsoft/TypeScript

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.