Skip to content

declareDecorator does not bring along getters and setters #148

Description

@schontz

If you use the declareDecorator on a class all the getters and setters are lost.

I was having issues making a PR so here is the updated version of https://github.com/dojo/typings/blob/master/examples/basicApp/src/app/declareDecorator.ts:

import dojoDeclare from 'dojo/_base/declare';

/**
 * A decorator that converts a TypeScript class into a declare constructor.
 * This allows declare constructors to be defined as classes, which nicely
 * hides away the `declare([], {})` boilerplate.
 */

export default function (... mixins: Object[]) {
	return function (target: Function) {
		let declared = dojoDeclare(mixins, target.prototype);

		// Bring getters and setters along for the ride
		Object.keys(target.prototype).forEach(key => {
			let descrip = Object.getOwnPropertyDescriptor(target.prototype, key);
			if (typeof descrip.get == 'function' || typeof descrip.set == 'function') {
				Object.defineProperty(declared.prototype, key, descrip);
			}
		});

		return declared;
	};
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions