The example at the end of the Inheriting from a class and implementing interfaces section of Chapter 4, Using Classes and Interfaces, uses the following interface:
interface ItemList {
appendItem(itemData: any): void;
prependItem(itemData: any): void;
appendBefore(node: HTMLElement, itemData: any): void;
appendAfter(node: HTMLElement, itemData: any): void;
removeItem(node: HTMLElement): void;
itemTemplate: (x: any) => HTMLElement;
readonly itemsParent: HTMLElement;
}
Various methods accept an itemData parameter, which represents a general data item whose fields have to be be used to assemble new elements to add to the DOM list represented by the interface. Its type is any since the data item may have any type. However, by using any, one misses several opportunities:
- The type of itemData can be any type but it is exactly the...