Tutorial by Examples

A class decorator is just a function that takes the class as its only argument and returns it after doing something with it: function log<T>(target: T) { // Do something with target console.log(target); // Return target return target; } We can then apply ...
This time we are going to declare a class decorator that will add some metadata to a class when we applied to it: function addMetadata(target: any) { // Add some metadata target.__customMetadata = { someKey: "someValue" }; // Return target ret...
We can wrap a class decorator with another function to allow customization: function addMetadata(metadata: any) { return function log(target: any) { // Add metadata target.__customMetadata = metadata; // Return target return target; ...

Page 1 of 1