Skip to content

Abstract getter/setter #11898

Closed
Closed
@dungdm93

Description

@dungdm93

TypeScript Version: 2.0.3

Code

abstract class Abstract {
    abstract set foo(value: string);
    abstract get bar(): string;
    abstract biz: number;
}

class Concrete extends Abstract {
    biz: number;
    constructor(public foo: string, public bar: string) {
        super();
        this.biz = 20;
    }

    toString(): string {
        return `${this.foo} ${this.bar}`;
    }
}

let i: Abstract = new Concrete("Hello", "World");
console.log(i.toString()); // undefined undefined

Expected behavior:
print Hello world

Actual behavior:
print undefined undefined

So look at Abstract class in JavaScript. foo & bar implementations are generated even they declared as abstract.

var Abstract = (function () {
    function Abstract() {
    }
    Object.defineProperty(Abstract.prototype, "foo", {
        set: function (value) { },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Abstract.prototype, "bar", {
        get: function () { },
        enumerable: true,
        configurable: true
    });
    return Abstract;
}());

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions