Further expressiveness with TypeScript decorators

In ES2015, we are able to decorate only classes, properties, methods, getters, and setters. TypeScript takes this further by allowing us to decorate functions or method parameters:

class Http { 
  // ... 
}
 
class GitHubApi { 
  constructor(@Inject(Http) http) { 
    // ... 
  } 
} 

Keep in mind that the parameter decorators should not alter any additional behavior. Instead, they are used to generate metadata. The most typical use case of these decorators is the dependency injection mechanism of Angular.

Get Getting Started with Angular - Second Edition 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.