-
Notifications
You must be signed in to change notification settings - Fork 13.2k
fix(lib/es2015): Fix definition of ProxyHandler
#35594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(lib/es2015): Fix definition of ProxyHandler
#35594
Conversation
src/lib/es2015.proxy.d.ts
Outdated
| interface ProxyHandler<T extends object> { | ||
| getPrototypeOf? (target: T): object | null; | ||
| setPrototypeOf? (target: T, v: any): boolean; | ||
| setPrototypeOf? (target: T, v: object | null): boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Proxy exotic object’s [[SetPrototypeOf]] ( V ) internal method ensures that V is object | null before passing it to user code.
src/lib/es2015.proxy.d.ts
Outdated
| get? (target: T, p: string | symbol, receiver: any): any; | ||
| set? (target: T, p: string | symbol, value: any, receiver: any): boolean; | ||
| deleteProperty? (target: T, p: string | symbol): boolean; | ||
| defineProperty? (target: T, p: string | symbol, attributes: PropertyDescriptor): boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Proxy exotic object doesn’t convert valid numeric indexes into numbers before passing them to user code, they remain as strings, which is how they’re actually implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numbers never really exist as object keys, it's probably the biggest "lie" in typescript 🤷♀
src/lib/es2015.proxy.d.ts
Outdated
| set? (target: T, p: string | symbol, value: any, receiver: any): boolean; | ||
| deleteProperty? (target: T, p: string | symbol): boolean; | ||
| defineProperty? (target: T, p: string | symbol, attributes: PropertyDescriptor): boolean; | ||
| ownKeys? (target: T): ArrayLike<string | symbol>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you return anything other that a string or symbol here, this will throw a TypeError at runtime (no, numbers don’t stringified here for whatever reason; see tc39/ecma262#1804 for discussion).
On the plus side, the spec doesn’t actually require that the returned value is an Array instance, just that it has a length property and doesn’t have holes.
src/lib/es2015.proxy.d.ts
Outdated
| defineProperty? (target: T, p: string | symbol, attributes: PropertyDescriptor): boolean; | ||
| ownKeys? (target: T): ArrayLike<string | symbol>; | ||
| apply? (target: T & ((...args: any[]) => any), thisArg: any, argArray: any[]): any; | ||
| construct? (target: T & (new (...args: any[]) => object), argArray: any[], newTarget?: any): object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These will only ever get called if the wrapped object is callable or constructable, respectively.
src/lib/es2015.proxy.d.ts
Outdated
| set? (target: T, p: PropertyKey, value: any, receiver: any): boolean; | ||
| deleteProperty? (target: T, p: PropertyKey): boolean; | ||
| defineProperty? (target: T, p: PropertyKey, attributes: PropertyDescriptor): boolean; | ||
| enumerate? (target: T): PropertyKey[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The enumerate(…) method was removed in ES2016 from both Reflect and ProxyHandlers, due to implementers deciding against it.
The type is wrong anyway, since it’s specified to return Iterator<any>.
PromiseHandlerProxyHandler
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
a15bf40 to
64743c4
Compare
This fixes several issues I found while comparing the definition of
ProxyHandlerto what’s actually defined in the specification.Depends on:
Reflect.enumerate(…)#38967 (merged)Reflectmethods #41987 (merged)Fixes #42894