I am facing an issue with setting up a Proxy
for an enum
. Specifically, I have an enum where I want to assign a value to this.status
using a Proxy. However, despite my expectations, the output "I have been set" does not appear in the console. Can anyone explain why this proxy behavior is not working on an enum?
export enum Status { Beginning, Middle, Ending }
export class MyClass {
public status = new Proxy(Status, {
set: (target, propertyKey, value) = {
console.log('I have been set')
return Reflect.set(target, propertyKey, value)
},
get: (target, propertyKey) => Reflect.get(target, propertyKey)
})
}
Here's how I'm trying to use it:
let c = new MyClass
c.status = Status.Middle
However, attempting to set it results in the error message:
Type 'Status.Middle' is not assignable to type 'typeof Status'.