super property: why doesn't this work as expected?

Topics: General
Dec 9, 2012 at 7:29 PM
Edited Dec 9, 2012 at 7:37 PM

I expected this contrived example to output "test executed!" and it does not:

module UI {

    export class AbstractCommand {

        private _isEnabled = true;

        constructor (public name: string) {
        }

        public get isEnabled(): bool {
            return this._isEnabled;
        }

        public set isEnabled(value: bool) {
            this._isEnabled = value;
        }

        public get canExecute(): bool {
            return this.isEnabled;
        }

        public execute() {
            // abstract
        }
		
        public trigger() {
            if (this.canExecute) {
                this.execute();
            }
        }

    }

    export class TestCommand extends AbstractCommand {

        constructor () {
            super("test");
        }
		
        public get canExecute(): bool {
            return super.canExecute;
        }

        public execute() {
            alert(this.name + " executed!");
        }

    }

}

var command = new UI.TestCommand();
command.trigger();

In the debugger, super.canExecute is undefined. What am I doing wrong? It works if I command out the overridden canExecute property in TestCommand or change it to return true.

It also works if I change canExecute to be a method instead of a property. So, is using super with ES5 properties busted in TypeScript?