Generic classes

Generic classes can be defined in the exactly same way as generic interfaces, by enclosing all generics inside the <> symbols, and then using them in the class definition. As an example of designing a complete application that uses both generic interfaces and classes, this section proposes rewriting the dom manipulation example at the end of the Inheriting from a class and implementing interfaces section of Chapter 4, Using Classes and Interfaces.

As discussed in the previous section, the ItemList interface can be redefined as a generic interface to avoid representing data items with the any type: 

interface ItemList<T> {    appendItem(itemData: T): void;    prependItem(itemData: T): void; appendBefore(node: HTMLElement, itemData: ...

Get Hands-On TypeScript for C# and .NET Core Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.