lib.es2015.proxy.d.ts (5251B)
1 /*! ***************************************************************************** 2 Copyright (c) Microsoft Corporation. All rights reserved. 3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 this file except in compliance with the License. You may obtain a copy of the 5 License at http://www.apache.org/licenses/LICENSE-2.0 6 7 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 MERCHANTABLITY OR NON-INFRINGEMENT. 11 12 See the Apache Version 2.0 License for specific language governing permissions 13 and limitations under the License. 14 ***************************************************************************** */ 15 16 17 /// <reference no-default-lib="true"/> 18 19 interface ProxyHandler<T extends object> { 20 /** 21 * A trap method for a function call. 22 * @param target The original callable object which is being proxied. 23 */ 24 apply?(target: T, thisArg: any, argArray: any[]): any; 25 26 /** 27 * A trap for the `new` operator. 28 * @param target The original object which is being proxied. 29 * @param newTarget The constructor that was originally called. 30 */ 31 construct?(target: T, argArray: any[], newTarget: Function): object; 32 33 /** 34 * A trap for `Object.defineProperty()`. 35 * @param target The original object which is being proxied. 36 * @returns A `Boolean` indicating whether or not the property has been defined. 37 */ 38 defineProperty?(target: T, property: string | symbol, attributes: PropertyDescriptor): boolean; 39 40 /** 41 * A trap for the `delete` operator. 42 * @param target The original object which is being proxied. 43 * @param p The name or `Symbol` of the property to delete. 44 * @returns A `Boolean` indicating whether or not the property was deleted. 45 */ 46 deleteProperty?(target: T, p: string | symbol): boolean; 47 48 /** 49 * A trap for getting a property value. 50 * @param target The original object which is being proxied. 51 * @param p The name or `Symbol` of the property to get. 52 * @param receiver The proxy or an object that inherits from the proxy. 53 */ 54 get?(target: T, p: string | symbol, receiver: any): any; 55 56 /** 57 * A trap for `Object.getOwnPropertyDescriptor()`. 58 * @param target The original object which is being proxied. 59 * @param p The name of the property whose description should be retrieved. 60 */ 61 getOwnPropertyDescriptor?(target: T, p: string | symbol): PropertyDescriptor | undefined; 62 63 /** 64 * A trap for the `[[GetPrototypeOf]]` internal method. 65 * @param target The original object which is being proxied. 66 */ 67 getPrototypeOf?(target: T): object | null; 68 69 /** 70 * A trap for the `in` operator. 71 * @param target The original object which is being proxied. 72 * @param p The name or `Symbol` of the property to check for existence. 73 */ 74 has?(target: T, p: string | symbol): boolean; 75 76 /** 77 * A trap for `Object.isExtensible()`. 78 * @param target The original object which is being proxied. 79 */ 80 isExtensible?(target: T): boolean; 81 82 /** 83 * A trap for `Reflect.ownKeys()`. 84 * @param target The original object which is being proxied. 85 */ 86 ownKeys?(target: T): ArrayLike<string | symbol>; 87 88 /** 89 * A trap for `Object.preventExtensions()`. 90 * @param target The original object which is being proxied. 91 */ 92 preventExtensions?(target: T): boolean; 93 94 /** 95 * A trap for setting a property value. 96 * @param target The original object which is being proxied. 97 * @param p The name or `Symbol` of the property to set. 98 * @param receiver The object to which the assignment was originally directed. 99 * @returns A `Boolean` indicating whether or not the property was set. 100 */ 101 set?(target: T, p: string | symbol, newValue: any, receiver: any): boolean; 102 103 /** 104 * A trap for `Object.setPrototypeOf()`. 105 * @param target The original object which is being proxied. 106 * @param newPrototype The object's new prototype or `null`. 107 */ 108 setPrototypeOf?(target: T, v: object | null): boolean; 109 } 110 111 interface ProxyConstructor { 112 /** 113 * Creates a revocable Proxy object. 114 * @param target A target object to wrap with Proxy. 115 * @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it. 116 */ 117 revocable<T extends object>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; }; 118 119 /** 120 * Creates a Proxy object. The Proxy object allows you to create an object that can be used in place of the 121 * original object, but which may redefine fundamental Object operations like getting, setting, and defining 122 * properties. Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs. 123 * @param target A target object to wrap with Proxy. 124 * @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it. 125 */ 126 new <T extends object>(target: T, handler: ProxyHandler<T>): T; 127 } 128 declare var Proxy: ProxyConstructor;