Generic objects

If your goal when adopting TypeScript is to create an API for client consumption, then generics are the language construct you should become the most familiar with. They allow consumers of frameworks and APIs to agree on a specific contract to accomplish a designated goal without having to know specific object types. Generics define the third and final category of objects in TypeScript, type parameters. As we saw earlier in this chapter when we discussed arrays, type parameters are defined inside of < and > characters. They can be used on interfaces or class definitions to create functionality for a broad set of object types that may or may not be known at the time of development. Let's say we wanted to create a generic task processor. ...

Get TypeScript Essentials 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.