The content within app.ts consists of simple functions as illustrated below:
function Log(target: any, propertyName: string | Symbol) {
console.log("Property decorator!");
console.log(target, propertyName);
}
function Log2(target: any, name: string, descriptor: PropertyDescriptor) {
console.log("Accessor decorator!");
console.log(target);
console.log(name);
console.log(descriptor);
}
function Log3(
target: any,
name: string | Symbol,
descriptor: PropertyDescriptor
) {
console.log("Method decorator!");
console.log(target);
console.log(name);
console.log(descriptor);
}
function Log4(target: any, name: string | Symbol, position: number) {
console.log("Parameter decorator!");
console.log(target);
console.log(name);
console.log(position);
}
class Product {
@Log
title: string;
private _price: number;
@Log2
set price(val: number) {
if (val > 0) {
this._price = val;
} else {
throw new Error("Invalid price - should be positive!");
}
}
constructor(t: string, p: number) {
this.title = t;
this._price = p;
}
@Log3
getPriceWithTax(@Log4 tax: number) {
return this._price * (1 + tax);
}
}
The challenge was addressed when I followed the instructions provided in this post by stating the target, eliminating the null reference, and obtaining accurate details.
tsc -t es5 -w app
viewed from the command line interface
Information displayed on the CLI