Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

declareDecorator does not bring along getters and setters #148

Open
schontz opened this issue Oct 11, 2018 · 0 comments
Open

declareDecorator does not bring along getters and setters #148

schontz opened this issue Oct 11, 2018 · 0 comments

Comments

@schontz
Copy link

schontz commented Oct 11, 2018

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;
	};
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant