Skip to content

Commit ea136c0

Browse files
committed
feat(lib/es2015): Add typed overloads to Reflect
1 parent 45b698b commit ea136c0

File tree

2 files changed

+119
-10
lines changed

2 files changed

+119
-10
lines changed

src/lib/es2015.reflect.d.ts

+116-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,124 @@
11
declare namespace Reflect {
2-
function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
3-
function construct(target: Function, argumentsList: ArrayLike<any>, newTarget?: any): any;
2+
/**
3+
* Calls the function with the specified object as the this value and the elements of specified array as the arguments.
4+
* @param target The function to call.
5+
* @param thisArgument The object to be used as the this object.
6+
* @param argumentsList An array of argument values to be passed to the function.
7+
*/
8+
function apply<T, A extends readonly any[], R>(
9+
target: (this: T, ...args: A) => R,
10+
thisArgument: T,
11+
argumentsList: Readonly<A>,
12+
): R;
13+
function apply(target: (...args: any) => any, thisArgument: any, argumentsList: ArrayLike<any>): any;
14+
15+
/**
16+
* Constructs the target with the elements of specified array as the arguments and the specified constructor as the `new.target` value.
17+
* @param target The function to call.
18+
* @param argumentsList An array of argument values to be passed to the function.
19+
* @param newTarget The constructor to be used as the `new.target` object.
20+
*/
21+
function construct<A extends readonly any[], R>(
22+
target: new (...args: A) => R,
23+
argumentsList: Readonly<A>,
24+
newTarget?: new (...args: any) => any,
25+
): R;
26+
function construct(target: new (...args: any) => any, argumentsList: ArrayLike<any>, newTarget?: new (...args: any) => any): any;
27+
28+
/**
29+
* Adds a property to an object, or modifies attributes of an existing property.
30+
* @param target Object on which to add or modify the property. This can be a native JavaScript object
31+
* (that is, a user-defined object or a built in object) or a DOM object.
32+
* @param propertyKey The property name.
33+
* @param attributes Descriptor for the property. It can be for a data property or an accessor property.
34+
*/
435
function defineProperty(target: object, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
36+
37+
/**
38+
* Removes a property from an object, equivalent to `delete target[propertyKey]`,
39+
* except it won't throw if `target[propertyKey]` is non-configurable.
40+
* @param target Object from which to remove the own property.
41+
* @param propertyKey The property name.
42+
*/
543
function deleteProperty(target: object, propertyKey: PropertyKey): boolean;
6-
function get(target: object, propertyKey: PropertyKey, receiver?: any): any;
7-
function getOwnPropertyDescriptor(target: object, propertyKey: PropertyKey): PropertyDescriptor | undefined;
8-
function getPrototypeOf(target: object): object;
44+
45+
/**
46+
* Gets the property of target, equivalent to `target[propertyKey]` when `receiver === target`.
47+
* @param target Object that contains the property on itself or in its prototype chain.
48+
* @param propertyKey The property name.
49+
* @param receiver The reference to use as the `this` value in the getter function,
50+
* if `target[propertyKey]` is an accessor property.
51+
*/
52+
function get<T extends object, P extends PropertyKey>(
53+
target: T,
54+
propertyKey: P,
55+
receiver?: unknown,
56+
): P extends keyof T ? T[P] : any;
57+
58+
/**
59+
* Gets the own property descriptor of the specified object.
60+
* An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype.
61+
* @param target Object that contains the property.
62+
* @param propertyKey The property name.
63+
*/
64+
function getOwnPropertyDescriptor<T extends object, P extends PropertyKey>(
65+
target: T,
66+
propertyKey: P,
67+
): TypedPropertyDescriptor<P extends keyof T ? T[P] : any> | undefined;
68+
69+
/**
70+
* Returns the prototype of an object.
71+
* @param target The object that references the prototype.
72+
*/
73+
function getPrototypeOf(target: object): object | null;
74+
75+
/**
76+
* Equivalent to `propertyKey in target`.
77+
* @param target Object that contains the property on itself or in its prototype chain.
78+
* @param propertyKey Name of the property.
79+
*/
980
function has(target: object, propertyKey: PropertyKey): boolean;
81+
82+
/**
83+
* Returns a value that indicates whether new properties can be added to an object.
84+
* @param target Object to test.
85+
*/
1086
function isExtensible(target: object): boolean;
11-
function ownKeys(target: object): PropertyKey[];
87+
88+
/**
89+
* Returns the keys of the own properties of an object. The own properties of an object are those that are defined directly
90+
* on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions.
91+
* @param target Object that contains the own properties.
92+
*/
93+
function ownKeys(target: object): (string | symbol)[];
94+
95+
/**
96+
* Prevents the addition of new properties to an object.
97+
* @param target Object to make non-extensible.
98+
* @return Whether the object has been made non-extensible.
99+
*/
12100
function preventExtensions(target: object): boolean;
101+
102+
/**
103+
* Sets the property of target, equivalent to `target[propertyKey] = value` when `receiver === target`.
104+
* @param target Object that contains the property on itself or in its prototype chain.
105+
* @param propertyKey Name of the property.
106+
* @param receiver The reference to use as the `this` value in the setter function,
107+
* if `target[propertyKey]` is an accessor property.
108+
*/
109+
function set<T extends object, P extends PropertyKey>(
110+
target: T,
111+
propertyKey: P,
112+
value: P extends keyof T ? T[P] : any,
113+
receiver?: any,
114+
): boolean;
13115
function set(target: object, propertyKey: PropertyKey, value: any, receiver?: any): boolean;
14-
function setPrototypeOf(target: object, proto: any): boolean;
116+
117+
/**
118+
* Sets the prototype of a specified object o to object proto or null.
119+
* @param target The object to change its prototype.
120+
* @param proto The value of the new prototype or null.
121+
* @return Whether setting the prototype was successful.
122+
*/
123+
function setPrototypeOf(target: object, proto: object | null): boolean;
15124
}

tests/baselines/reference/modularizeLibrary_UsingES5LibAndES6FeatureLibs.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ var p = new Proxy(t, {});
1616
>{} : {}
1717

1818
Reflect.ownKeys({});
19-
>Reflect.ownKeys({}) : (string | number | symbol)[]
20-
>Reflect.ownKeys : (target: object) => (string | number | symbol)[]
19+
>Reflect.ownKeys({}) : (string | symbol)[]
20+
>Reflect.ownKeys : (target: object) => (string | symbol)[]
2121
>Reflect : typeof Reflect
22-
>ownKeys : (target: object) => (string | number | symbol)[]
22+
>ownKeys : (target: object) => (string | symbol)[]
2323
>{} : {}
2424

2525
function* idGen() {

0 commit comments

Comments
 (0)