Skip to content

Proxied observable class prevents altering descriptors in getOwnPropertyDescriptor trap while proxied observable object allows. #3742

@n-lark

Description

@n-lark

Intended outcome:

Attempting to proxy an instance of a class, and within that proxy change the enumerability of specific keys through getOwnPropertyDescriptor trap.

Actual outcome:

See codeSandbox, when proxying the instance of a class, any attempts to alter the enumerability of an observable property through getOwnPropertyDescriptor trap throws the error:

TypeError: 'getOwnPropertyDescriptor' on proxy: trap returned descriptor for property 'id' that is incompatible with the existing property in the proxy target

This works with basic objects, however something about classes prevents the altering of any enumerability through the proxy. I believe this may be intentional, due to the warning given for the linting option safeDescriptors:

MobX makes some fields non-configurable or non-writable to prevent you from doing things that are not supported or would most likely break your code.

Is this a bug or is this intentional behavior? I would like to find a way to make this possible for my use case with classes, and it seems strange that objects would allow this but classes wouldn't. Any guidance is appreciated.

How to reproduce the issue:

See codeSandbox.

Also, I apologize if this isn't really a bug and more of a question.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions