deeleman / learning-angular2

Code samples repository for the examples provided in "Learning Angular 2", published by Packt Publishing - THE BOOK COVERS UP TO RC.1 and hence is severely OUTDATED. PLEASE REFER TO THE LATEST EDITIONS INSTEAD.
https://www.packtpub.com/web-development/learning-angular-2
108 stars 59 forks source link

Chapter 2 section 5 - Method type #28

Closed RichLinnell closed 8 years ago

RichLinnell commented 8 years ago

Should the LogOutput decorator signature be function LogOutput(target: Object, key: string, descriptor: any) instead of function LogOutput(target: Funciton, key: string, descriptor: any)

if I use the latter then I get compiler warnings in its usage.

deeleman commented 8 years ago

The target parameter refers to (official documentation cited below):

Either the constructor function of the class for a static member, or the prototype of the class for an instance member.

So for the sake of providing a more self-descriptive code, annotating the target parameter as a Functiontype (please note the typo in your example) is correct (ultimately the decorator will target a function, which is what a class is in the form of its constructor in ES5). Anyways, annotating the parameter as Object will ensure your function works well in any scenario. The official documentation actually recommends using any.