Skip to content

Commit

Permalink
feat(lib/es2015): Add typed overloads to Reflect (#35608)
Browse files Browse the repository at this point in the history
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
  • Loading branch information
ExE-Boss and sandersn authored Aug 9, 2022
1 parent 19e2a31 commit a123fc5
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/lib/es2015.reflect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ declare namespace Reflect {
* @param thisArgument The object to be used as the this object.
* @param argumentsList An array of argument values to be passed to the function.
*/
function apply<T, A extends readonly any[], R>(
target: (this: T, ...args: A) => R,
thisArgument: T,
argumentsList: Readonly<A>,
): R;
function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;

/**
Expand All @@ -15,6 +20,11 @@ declare namespace Reflect {
* @param argumentsList An array of argument values to be passed to the constructor.
* @param newTarget The constructor to be used as the `new.target` object.
*/
function construct<A extends readonly any[], R>(
target: new (...args: A) => R,
argumentsList: Readonly<A>,
newTarget?: new (...args: any) => any,
): R;
function construct(target: Function, argumentsList: ArrayLike<any>, newTarget?: Function): any;

/**
Expand All @@ -41,15 +51,22 @@ declare namespace Reflect {
* @param receiver The reference to use as the `this` value in the getter function,
* if `target[propertyKey]` is an accessor property.
*/
function get(target: object, propertyKey: PropertyKey, receiver?: any): any;
function get<T extends object, P extends PropertyKey>(
target: T,
propertyKey: P,
receiver?: unknown,
): P extends keyof T ? T[P] : any;

/**
* Gets the own property descriptor of the specified object.
* An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype.
* @param target Object that contains the property.
* @param propertyKey The property name.
*/
function getOwnPropertyDescriptor(target: object, propertyKey: PropertyKey): PropertyDescriptor | undefined;
function getOwnPropertyDescriptor<T extends object, P extends PropertyKey>(
target: T,
propertyKey: P,
): TypedPropertyDescriptor<P extends keyof T ? T[P] : any> | undefined;

/**
* Returns the prototype of an object.
Expand Down Expand Up @@ -91,6 +108,12 @@ declare namespace Reflect {
* @param receiver The reference to use as the `this` value in the setter function,
* if `target[propertyKey]` is an accessor property.
*/
function set<T extends object, P extends PropertyKey>(
target: T,
propertyKey: P,
value: P extends keyof T ? T[P] : any,
receiver?: any,
): boolean;
function set(target: object, propertyKey: PropertyKey, value: any, receiver?: any): boolean;

/**
Expand Down

0 comments on commit a123fc5

Please sign in to comment.