In the beginning of the section on using static typing, we mentioned the type parameters. In order to get a better understanding of them, let's begin with an example. Let's suppose that we want to implement the classical data structure BinarySearchTree. Let's define its interface using a class without applying any method implementations:
class Node { value: any; left: Node; right: Node; } class BinarySearchTree { private root: Node; insert(any: value): void { /* ... */ } remove(any: value): void { /* ... */ } exists(any: value): boolean { /* ... */ } inorder(callback: {(value: any): void}): void { /* ... */ } }
In the preceding snippet, we defined a class called Node. The instances of this class represent the individual nodes in our tree. Each node has a left and right child nodes and a value...