Skip to content

Update Array#forEach: use a generic type parameter to ensure elements are inferred correctly #55202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

shogunsea
Copy link

Fixes #55201

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jul 29, 2023
@shogunsea shogunsea marked this pull request as ready for review July 29, 2023 23:05
@@ -1237,7 +1237,7 @@ interface ReadonlyArray<T> {
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
forEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void;
forEach<U>(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type argument isn't used anywhere.

@MartinJohns
Copy link
Contributor

See #16223, where the generic argument for forEach was explicitly removed again for performance reasons.

@shogunsea shogunsea closed this Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Array.forEach incorrectly narrows the inferred type when elements are annotated with union type
3 participants