User Tools

Site Tools


Typescript transformation sample

Original TS

bar.ts
class Bar {
    private _percent: number = 0
 
    constructor() {
    }
 
    get percent() : number {
        return this._percent
    }
 
    set percent(percent : number) {
        this._percent = percent
    }
 
    getPercent() : number {
        return this._percent
    }
 
    setPercent(percent : number) : void {
        this._percent = percent
    }
}
 
let bar = new Bar()
let some : number
 
some = bar.percent
console.log(some)
 
bar.percent = 12
 
console.log(bar.percent)

Compiled to ES6+

bar-es2017.js
class Bar {
    constructor() {
        this._percent = 0;
    }
    get percent() {
        return this._percent;
    }
    set percent(percent) {
        this._percent = percent;
    }
    getPercent() {
        return this._percent;
    }
    setPercent(percent) {
        this._percent = percent;
    }
}
let bar = new Bar();
let some;
some = bar.percent;
console.log(some);
bar.percent = 12;
console.log(bar.percent);

Compiled to ES5

bar-es5.js
var Bar = /** @class */ (function () {
    function Bar() {
        this._percent = 0;
    }
    Object.defineProperty(Bar.prototype, "percent", {
        get: function () {
            return this._percent;
        },
        set: function (percent) {
            this._percent = percent;
        },
        enumerable: true,
        configurable: true
    });
    Bar.prototype.getPercent = function () {
        return this._percent;
    };
    Bar.prototype.setPercent = function (percent) {
        this._percent = percent;
    };
    return Bar;
}());
var bar = new Bar();
var some;
some = bar.percent;
console.log(some);
bar.percent = 12;
console.log(bar.percent);

First PagePrevious PageBack to overviewNext PageLast Page