Skip to content

fix(#20846 lib/es2015): override new Proxy<T, U> #44458

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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/lib/es2015.proxy.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
interface ProxyHandler<T extends object> {
interface ProxyHandler<T extends object, U extends object> {
apply?(target: T, thisArg: any, argArray: any[]): any;
construct?(target: T, argArray: any[], newTarget: Function): object;
defineProperty?(target: T, p: string | symbol, attributes: PropertyDescriptor): boolean;
deleteProperty?(target: T, p: string | symbol): boolean;
get?(target: T, p: string | symbol, receiver: any): any;
get?<K extends keyof U>(target: T, p: K, receiver: U): U[K];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test for the program in the original bug? (#20846)
I don't understand how inference of U would work to fix the bug for that program, since in that case there is no receiver.

getOwnPropertyDescriptor?(target: T, p: string | symbol): PropertyDescriptor | undefined;
getPrototypeOf?(target: T): object | null;
has?(target: T, p: string | symbol): boolean;
isExtensible?(target: T): boolean;
ownKeys?(target: T): ArrayLike<string | symbol>;
preventExtensions?(target: T): boolean;
set?(target: T, p: string | symbol, value: any, receiver: any): boolean;
set?<K extends keyof U>(target: T, p: K, value: U[K], receiver: U): boolean;
setPrototypeOf?(target: T, v: object | null): boolean;
}

interface ProxyConstructor {
revocable<T extends object>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
new <T extends object>(target: T, handler: ProxyHandler<T>): T;
revocable<T extends object>(target: T, handler: ProxyHandler<T, any>): { proxy: T; revoke: () => void; };
revocable<T extends object, U extends object>(target: T, handler: ProxyHandler<T, U>): { proxy: U; revoke: () => void; };
new <T extends object>(target: T, handler: ProxyHandler<T, any>): T;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't immediately see how this ordering of overloads would work. Could you add tests where TypeScript choses one vs the other overload signatures?

new <T extends object, U extends object>(target: T, handler: ProxyHandler<T, U>): U;
}
declare var Proxy: ProxyConstructor;