Skip to content

Commit b4eacf4

Browse files
docs: expand TypeScript generics section with examples of invalid type arguments
New code examples showing a typical TypeScript mistake of passing incompatible types that violates a generics' constraint.
1 parent 0d96441 commit b4eacf4

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

packages/documentation/copy/en/handbook-v2/More on Functions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ const longerArray = longest([1, 2], [1, 2, 3]);
190190
const longerString = longest("alice", "bob");
191191
// Error! Numbers don't have a 'length' property
192192
const notOK = longest(10, 100);
193+
// Error! An array of numbers and a string can't be compared
194+
const alsoNotOK = longest([1, 2], 'alice');
193195
```
194196

195197
There are a few interesting things to note in this example.
@@ -887,3 +889,4 @@ const f3 = function (): void {
887889
For more on `void` please refer to these other documentation entries:
888890

889891
- [FAQ - "Why are functions returning non-void assignable to function returning void?"](https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-functions-returning-non-void-assignable-to-function-returning-void)
892+

0 commit comments

Comments
 (0)