Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

typescript decorators

tsfunction f() {
  console.log("f(): evaluated");
  return function(target, propertyKey: string, descriptor: PropertyDescriptor) {
    console.log("f(): called");
  };
}

function g() {
  console.log("g(): evaluated");
  return function(target, propertyKey: string, descriptor: PropertyDescriptor) {
    console.log("g(): called");
  };
}

class C {
  @f()
  @g()
  method() {}
}
Comment

simple typescript decorator example

// Example of a Class Decorator in TypeScript:
function reportableClassDecorator<T extends { new (...args: any[]): {} }>(constructor: T) {
  return class extends constructor {
    reportingURL = "http://www...";
  };
}
 
@reportableClassDecorator
class BugReport {
  title: string;
  constructor(t: string) {
    this.title = t;
  }
}
 
const bug = new BugReport("Needs dark mode");
console.log(bug.title); // Prints "Needs dark mode"
console.log(bug.reportingURL); // Prints "http://www..."
Comment

PREVIOUS NEXT
Code Example
Typescript :: node js process on unhandled promise rejection 
Typescript :: check anagramm in typescript 
Typescript :: enum in ts 
Typescript :: laravel many to many get related posts by category 
Typescript :: what are google extensions 
Typescript :: get a list of all email accounts in cpanel 
Typescript :: create mock promise angular 
Typescript :: angular 12 model class 
Typescript :: typescript returntype remove promise 
Typescript :: typescript type number range 
Typescript :: typescript final example 
Typescript :: typescript variables 
Typescript :: contract method calling with ether.js 
Typescript :: git squash commits on branch 
Typescript :: typescript get all enum keys 
Typescript :: array containing objects with matching elements 
Typescript :: typescript open site in frame 
Typescript :: whats ruby used for 
Typescript :: when a vector in c++ is resized what happens to the elements of the vector 
Typescript :: angular cancel http request 
Typescript :: Warning: call_user_func_array() expects parameter 1 to be a valid callback 
Typescript :: formgroup check if valid 
Typescript :: readonly in typescript 
Typescript :: Start Angular App In Localhost 
Typescript :: __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ 
Typescript :: how to reset windows update components in windows 
Typescript :: difference in minutes between 2 time inputs laravel 
Typescript :: split in angular 8 
Typescript :: 8.1.3. Varying Data Types&para; Arrays 
Typescript :: Roblox Script wait 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =