A lot of JavaScript user code assumes that you can pass arbitrary values where JavaScript expects property keys.
Examples:
Object.defineProperty(…)Object.getOwnPropertyDescriptor(…)Reflect.defineProperty(…)Reflect.deleteProperty(…)Reflect.get(…)Reflect.getOwnPropertyDescriptor(…)Reflect.has(…)Reflect.set(…)This makes [[ProxyHandler]].ownKeys(…) into a footgun, as user code might assume that the contents of the returned array‑like will be processed by ToPropertyKey(…), instead of throwing when it encounters a value that is neither a string, nor a symbol, like it does currently.
See also: https://github.com/microsoft/TypeScript/pull/35594
Without historical context on how the decision was made, it could be seen as an instance of robustness principle (Postel's law): the functions that you listed (consumers of property keys) are liberal in what they accept, but we require the proxy hooks to be conservative in what they produce.
cc @erights @tvcutsem
Most helpful comment
Without historical context on how the decision was made, it could be seen as an instance of robustness principle (Postel's law): the functions that you listed (consumers of property keys) are liberal in what they accept, but we require the proxy hooks to be conservative in what they produce.