From 466df658fea128bc749cb232fb3c6914bf338578 Mon Sep 17 00:00:00 2001 From: Shan Wijenayaka Date: Sat, 24 May 2025 23:58:36 +0800 Subject: [PATCH] fix: update myForEach example to use generics instead of any --- .../documentation/copy/en/handbook-v2/More on Functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/documentation/copy/en/handbook-v2/More on Functions.md b/packages/documentation/copy/en/handbook-v2/More on Functions.md index 4d40edb5bada..6ca7050fbd6f 100644 --- a/packages/documentation/copy/en/handbook-v2/More on Functions.md +++ b/packages/documentation/copy/en/handbook-v2/More on Functions.md @@ -394,7 +394,7 @@ f(undefined); Once you've learned about optional parameters and function type expressions, it's very easy to make the following mistakes when writing functions that invoke callbacks: ```ts twoslash -function myForEach(arr: any[], callback: (arg: any, index?: number) => void) { +function myForEach(arr: T[], callback: (arg: T, index?: number) => void) { for (let i = 0; i < arr.length; i++) { callback(arr[i], i); } @@ -419,7 +419,7 @@ In other words, the function definition says that the implementation might look ```ts twoslash // @errors: 2532 18048 -function myForEach(arr: any[], callback: (arg: any, index?: number) => void) { +function myForEach(arr: T[], callback: (arg: T, index?: number) => void) { for (let i = 0; i < arr.length; i++) { // I don't feel like providing the index today callback(arr[i]);