Skip to content

Commit 78e2bfd

Browse files
Fix(49525): Adds documentation for the Proxy type. (#49674)
* Adds documentation for the Proxy type. * Removed trailing whitespace. * Addresses PR feedback. * Removes trivial comments and adds descriptive names.
1 parent 3afe2d6 commit 78e2bfd

File tree

1 file changed

+91
-2
lines changed

1 file changed

+91
-2
lines changed

src/lib/es2015.proxy.d.ts

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,110 @@
11
interface ProxyHandler<T extends object> {
2+
/**
3+
* A trap method for a function call.
4+
* @param target The original callable object which is being proxied.
5+
*/
26
apply?(target: T, thisArg: any, argArray: any[]): any;
7+
8+
/**
9+
* A trap for the `new` operator.
10+
* @param target The original object which is being proxied.
11+
* @param newTarget The constructor that was originally called.
12+
*/
313
construct?(target: T, argArray: any[], newTarget: Function): object;
4-
defineProperty?(target: T, p: string | symbol, attributes: PropertyDescriptor): boolean;
14+
15+
/**
16+
* A trap for `Object.defineProperty()`.
17+
* @param target The original object which is being proxied.
18+
* @returns A `Boolean` indicating whether or not the property has been defined.
19+
*/
20+
defineProperty?(target: T, property: string | symbol, attributes: PropertyDescriptor): boolean;
21+
22+
/**
23+
* A trap for the `delete` operator.
24+
* @param target The original object which is being proxied.
25+
* @param p The name or `Symbol` of the property to delete.
26+
* @returns A `Boolean` indicating whether or not the property was deleted.
27+
*/
528
deleteProperty?(target: T, p: string | symbol): boolean;
29+
30+
/**
31+
* A trap for getting a property value.
32+
* @param target The original object which is being proxied.
33+
* @param p The name or `Symbol` of the property to get.
34+
* @param receiver The proxy or an object that inherits from the proxy.
35+
*/
636
get?(target: T, p: string | symbol, receiver: any): any;
37+
38+
/**
39+
* A trap for `Object.getOwnPropertyDescriptor()`.
40+
* @param target The original object which is being proxied.
41+
* @param p The name of the property whose description should be retrieved.
42+
*/
743
getOwnPropertyDescriptor?(target: T, p: string | symbol): PropertyDescriptor | undefined;
44+
45+
/**
46+
* A trap for the `[[GetPrototypeOf]]` internal method.
47+
* @param target The original object which is being proxied.
48+
*/
849
getPrototypeOf?(target: T): object | null;
50+
51+
/**
52+
* A trap for the `in` operator.
53+
* @param target The original object which is being proxied.
54+
* @param p The name or `Symbol` of the property to check for existence.
55+
*/
956
has?(target: T, p: string | symbol): boolean;
57+
58+
/**
59+
* A trap for `Object.isExtensible()`.
60+
* @param target The original object which is being proxied.
61+
*/
1062
isExtensible?(target: T): boolean;
63+
64+
/**
65+
* A trap for `Reflect.ownKeys()`.
66+
* @param target The original object which is being proxied.
67+
*/
1168
ownKeys?(target: T): ArrayLike<string | symbol>;
69+
70+
/**
71+
* A trap for `Object.preventExtensions()`.
72+
* @param target The original object which is being proxied.
73+
*/
1274
preventExtensions?(target: T): boolean;
13-
set?(target: T, p: string | symbol, value: any, receiver: any): boolean;
75+
76+
/**
77+
* A trap for setting a property value.
78+
* @param target The original object which is being proxied.
79+
* @param p The name or `Symbol` of the property to set.
80+
* @param receiver The object to which the assignment was originally directed.
81+
* @returns `A `Boolean` indicating whether or not the property was set.
82+
*/
83+
set?(target: T, p: string | symbol, newValue: any, receiver: any): boolean;
84+
85+
/**
86+
* A trap for `Object.setPrototypeOf()`.
87+
* @param target The original object which is being proxied.
88+
* @param newPrototype The object's new prototype or `null`.
89+
*/
1490
setPrototypeOf?(target: T, v: object | null): boolean;
1591
}
1692

1793
interface ProxyConstructor {
94+
/**
95+
* Creates a revocable Proxy object.
96+
* @param target A target object to wrap with Proxy.
97+
* @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
98+
*/
1899
revocable<T extends object>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
100+
101+
/**
102+
* Creates a Proxy object. The Proxy object allows you to create an object that can be used in place of the
103+
* original object, but which may redefine fundamental Object operations like getting, setting, and defining
104+
* properties. Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs.
105+
* @param target A target object to wrap with Proxy.
106+
* @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
107+
*/
19108
new <T extends object>(target: T, handler: ProxyHandler<T>): T;
20109
}
21110
declare var Proxy: ProxyConstructor;

0 commit comments

Comments
 (0)