From 8a0d279c1cf8f72008d645575e32237333b53a8a Mon Sep 17 00:00:00 2001 From: yoKurt94 <62561593+yoKurt94@users.noreply.github.com> Date: Thu, 15 May 2025 13:25:48 +0200 Subject: [PATCH 1/2] Clarify type inference behavior in 'Push Type Parameters Down' example Improved the explanation of why firstElement2 returns any by simplifying the explanation. --- packages/documentation/copy/en/handbook-v2/More on Functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..f9163ef4d02b 100644 --- a/packages/documentation/copy/en/handbook-v2/More on Functions.md +++ b/packages/documentation/copy/en/handbook-v2/More on Functions.md @@ -292,7 +292,7 @@ const b = firstElement2([1, 2, 3]); ``` These might seem identical at first glance, but `firstElement1` is a much better way to write this function. -Its inferred return type is `Type`, but `firstElement2`'s inferred return type is `any` because TypeScript has to resolve the `arr[0]` expression using the constraint type, rather than "waiting" to resolve the element during a call. +Its inferred return type is `Type`, but `firstElement2`'s inferred return type is `any` because TypeScript uses the constraint type `any[]`, rather than `Type`, when resolving the `arr[0]` expression. > **Rule**: When possible, use the type parameter itself rather than constraining it From 7823105146da5905e33d446ced1a5af6b9e59d6d Mon Sep 17 00:00:00 2001 From: yoKurt94 <62561593+yoKurt94@users.noreply.github.com> Date: Thu, 15 May 2025 14:11:20 +0200 Subject: [PATCH 2/2] Clarify type inference behavior in 'Push Type Parameters Down' section Improved the explanation of why returns by simplifying the sentence. --- packages/documentation/copy/en/handbook-v2/More on Functions.md | 1 + 1 file changed, 1 insertion(+) 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 f9163ef4d02b..0898da15cd91 100644 --- a/packages/documentation/copy/en/handbook-v2/More on Functions.md +++ b/packages/documentation/copy/en/handbook-v2/More on Functions.md @@ -294,6 +294,7 @@ const b = firstElement2([1, 2, 3]); These might seem identical at first glance, but `firstElement1` is a much better way to write this function. Its inferred return type is `Type`, but `firstElement2`'s inferred return type is `any` because TypeScript uses the constraint type `any[]`, rather than `Type`, when resolving the `arr[0]` expression. + > **Rule**: When possible, use the type parameter itself rather than constraining it #### Use Fewer Type Parameters