TypeScript. Decorators

Home » Tutorials » JavaScript » TypeScript. Decorators
In this tutorial we’ll discuss decorators in TypeScript and consider some its use examples.
Decorators are experimental but very powerful part of TypeScript language. Decorators are very important part of such a javascript framework – Angular. In TypeScript decorator is function, which can add some meta information or change entity’s behavior, which this decorator applies (class, class method, class property etc).
Код урока
function myDecorator(target: Function): any {
    const newConstructor: Function = function (name: string) {
        this.name = 'Hello, ' + name;
        setInterval(() => console.log(1), 1000);
    return newConstructor;

function sumDecorator(target: Object, method: string) {

class Programmer {
    lang = 'typescript';
    name: string;

    constructor(name) {
        this.name = name;

    // @ts-ignore
    // @sumDecorator
    add(a: number, b: number) {
        return a + b;

let kamil = new Programmer('Kamil');

const res = kamil.add(1, 2);


Submit a Comment

Your email address will not be published. Required fields are marked *

Подписаться на рассылку

Будьте в курсе - получайте последние статьи на свой email

Ваша подписка успешно оформлена

Pin It on Pinterest

Share This