I need my getters & setters to be enumerable, however, TypeScript emits ES6 class syntax, and class properties are not enumerable in javascript.
Is there a typescript config or something else I can do that forces class properties to be emitted as Object.defineProperty()
with enumerable: true
?
Edit: It looks like this can be achieved with property decorators, how might that be done in this case?
Example:
class User {
public roles: string[];
get isAdmin() {
return this.roles.some((role) => role === 'admin');
}
}
// This should be `true` not `false`
console.log(Object.keys(new User()).includes("isAdmin"))
If a User
instance gets passed into a Vuex store for instance, the non-enumerable members are dropped, and isAdmin
no longer exists.