microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.71k stars 12.45k forks source link

Array<T>.reduce<U> method description contains mismatched parameter in description #55077

Open MihailSandulescu opened 1 year ago

MihailSandulescu commented 1 year ago

Bug Report

file node_modules/typescript/lib/lib.es5.d.ts, lines 1386, 1392, 1393, 1399. ParameterpreviousValue of the callbackfn in reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T) method is named accumulator in the JSDoc, instead of previousValue, potentially causing confusion when reading the documentation provided.

πŸ”Ž Search Terms

Array<T>.reduce<U>, Array<T>.reduce<U>(callbackfn:(previousValue, accumulator

πŸ•— Version & Regression Information

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// Welcome to the TypeScript Playground, this is a website
// which gives you a chance to write, share and learn TypeScript.

// You could think of it in three ways:
//
//  - A location to learn TypeScript where nothing can break
//  - A place to experiment with TypeScript syntax, and share the URLs with others
//  - A sandbox to experiment with different compiler features of TypeScript

const anExampleVariable = "Hello World"
console.log(anExampleVariable)

const arr = ['foo', 'bar', 'baz', 'acc'];

const reduceArr = arr.reduce((prev, curr) => {return prev.concat(curr);});

// To learn more about the language, click above in "Examples" or "What's New".
// Otherwise, get started by removing these comments and the world is your playground.

πŸ™ Actual behavior

previousValue parameter of callbackfn is named accumulator in JSDoc

πŸ™‚ Expected behavior

Either previousValue parameter of callbackfn should be named previousValue in JSDoc, or the parameter of callbackfn should be renamed to accumulator, in order to avoid confusion.

kirillkurko commented 1 year ago

Can I try to take this one and address it?

JoshuaKGoldberg commented 1 year ago

@kirillkurko see https://github.com/microsoft/TypeScript/blob/634d3a1db5c69c1425119a74045790a4d1dc3046/CONTRIBUTING.md#issue-claiming, you can just get started working on issues marked Help Wanted πŸ™‚. Are you still interested in this one?