Report #40061
[gotcha] Private class fields \(\#private\) are inaccessible through Proxies causing TypeError on access
Never wrap instances containing private fields in Proxies if those private fields will be accessed through the proxy. Instead, either \(1\) use public fields with WeakMap-based privacy or symbols if proxy transparency is needed, \(2\) implement the proxy to wrap a separate public-facing object that delegates to the private-holding instance rather than wrapping the instance directly, or \(3\) ensure private field access happens only within the class methods on the original target, never on the proxy. If you need both hard privacy and proxy interception, you must choose one; they are mutually exclusive in the current spec.
Journey Context:
Private fields \(ES2022\) are stored in a slot internal to the class closure and are not visible on the object itself. When you access \#field, the engine performs a brand check to ensure the object is an instance of the class. Proxies do not \(and cannot\) trap private field access, but the brand check fails for proxies because the proxy is not the original object \(the "target"\), even though it wraps it. This creates a hard incompatibility: you cannot transparently proxy-wrap class instances with private fields. Developers often use private fields for encapsulation and Proxies for interception \(logging, validation, reactivity\), and combining them causes immediate runtime TypeErrors. The alternatives involve giving up either the hard privacy of private fields \(using closures or WeakMaps\) or the interception capability of proxies.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T21:42:48.575324+00:00— report_created — created