|
// extensions to global Reflect object |
|
declare namespace Reflect { |
|
function mirror(value: (...args: any[]) => any): FunctionMirror; |
|
function mirror(value: new (...args: any[]) => any): ClassMirror; |
|
function mirror(value: any): ObjectMirror; |
|
function mirror(value: any, propertyKey: PropertyKey): MemberMirror; |
|
} |
|
|
|
// Extensions to the Object() constructor function object. |
|
interface ObjectConstructor { |
|
mirror(value: (...args: any[]) => any): FunctionMirror; |
|
mirror(value: new (...args: any[]) => any): ClassMirror; |
|
mirror(value: any): ObjectMirror; |
|
mirror(value: any, propertyKey: PropertyKey): MemberMirror; |
|
} |
|
|
|
// Base mirror API |
|
interface Mirror { |
|
/*readonly*/ kind: string; |
|
/*readonly*/ state: "initializing" | "initialized"; |
|
|
|
// Mirror API for metadata |
|
defineMetadata(key: any, value: any): void; |
|
deleteMetadata(key: any): boolean; |
|
hasMetadata(key: any): boolean; |
|
getMetadata(key: any): any; |
|
hasOwnMetadata(key: any): boolean; |
|
getOwnMetadata(key: any): any; |
|
getOwnMetadataKeys(): any[]; |
|
} |
|
|
|
// Base mirror for a function, class, or object literal. |
|
interface ObjectMirror extends Mirror { |
|
/*readonly*/ kind: "function" | "class" | "prototype" | "object"; |
|
|
|
// Mirror API for objects |
|
isPrototypeOf(other: any): boolean; // from Object |
|
getPrototype(): ObjectMirror; // from ObjectConstructor (getPrototypeOf) |
|
setPrototype(proto: any): boolean; // from Reflect (setPrototypeOf) |
|
isExtensible(): boolean; // from ObjectConstructor |
|
preventExtensions(): boolean; // from ObjectConstructor |
|
|
|
// Mirror API for object properties |
|
defineProperty(propertyKey: PropertyKey, descriptor: PropertyDescriptor): PropertyMirror; // from ObjectConstructor |
|
deleteProperty(propertyKey: PropertyKey): boolean; // from Reflect |
|
hasOwnProperty(propertyKey: PropertyKey): boolean; // from Object |
|
getOwnPropertyDescriptor(propertyKey: PropertyKey): PropertyDescriptor; // from ObjectConstructor |
|
getOwnProperty(propertyKey: PropertyKey): PropertyMirror; // from ObjectConstructor |
|
getOwnProperties(): PropertyMirror[]; |
|
getOwnPropertyKeys(): PropertyKey[]; // from ObjectConstructor (getOwnPropertyNames/getOwnPropertySymbols) |
|
has(propertyKey: PropertyKey): boolean; // from Reflect |
|
get(propertyKey: PropertyKey, receiver?: any): any; // from Reflect |
|
set(propertyKey: PropertyKey, value: any, receiver?: any): boolean; // from Reflect |
|
ownKeys(): PropertyKey[]; // from Reflect |
|
enumerate(): IterableIterator<any>; // from Reflect |
|
} |
|
|
|
// Mirror for a function |
|
interface FunctionMirror extends ObjectMirror { |
|
/*readonly*/ kind: "function"; |
|
/*readonly*/ name: string; |
|
/*readonly*/ prototype: ObjectMirror; // undefined if arrow function |
|
/*readonly*/ length: number; |
|
/*readonly*/ generator: boolean; // true if generator function |
|
/*readonly*/ async: boolean; // true if async function |
|
/*readonly*/ arrow: boolean; // true if arrow function |
|
|
|
// Properties used during function declaration initialization. |
|
value: Function; // Set throws if not initializing (see Mirror.state). |
|
|
|
// Mirror API for parameters |
|
getParameters(): ParameterMirror[]; |
|
|
|
// Mirror API for functions |
|
construct(argumentsList: ArrayLike<any>, newTarget?: any): any; // from Reflect |
|
apply(thisArg: any, argArray?: any): any; // from Function |
|
call(thisArg: any, ...argArray: any[]): any; // from Function |
|
bind(thisArg: any, ...argArray: any[]): any; // from Function |
|
[Symbol.hasInstance](value: any): boolean; // from Function |
|
} |
|
|
|
// Mirror for a class |
|
interface ClassMirror extends ObjectMirror { |
|
/*readonly*/ kind: "class"; |
|
/*readonly*/ name: string; |
|
/*readonly*/ length: number; |
|
/*readonly*/ prototype: PrototypeMirror; |
|
|
|
// Properties used during class declaration initialization |
|
constructor: Function; // Set throws if not initializing (see Mirror.state). |
|
|
|
// Mirror API for parameters |
|
getParameters(): ParameterMirror[]; |
|
|
|
// Mirror API for constructors |
|
construct(argumentsList: ArrayLike<any>, newTarget?: any): any; // from Reflect |
|
apply(thisArg: any, argArray?: any): any; // from Function |
|
call(thisArg: any, ...argArray: any[]): any; // from Function |
|
bind(thisArg: any, ...argArray: any[]): any; // from Function |
|
[Symbol.hasInstance](value: any): boolean; // from Function |
|
|
|
// Mirror API for static fields |
|
defineField(propertyKey: PropertyKey): FieldMirror; // Throws if not initializing (see Mirror.state). |
|
deleteField(propertyKey: PropertyKey): boolean; // Ignored if not initializing (see Mirror.state). |
|
hasOwnField(propertyKey: PropertyKey): boolean; |
|
getOwnField(propertyKey: PropertyKey): FieldMirror; |
|
getOwnFields(): FieldMirror[]; |
|
getOwnFieldKeys(): PropertyKey[]; |
|
|
|
// Mirror API for static private state |
|
defineSlot(name?: string): SlotMirror; // Throws if not initializing (see Mirror.state). |
|
} |
|
|
|
// Mirror for a class prototype and instance members |
|
interface PrototypeMirror extends ObjectMirror { |
|
/*readonly*/ kind: "prototype"; |
|
/*readonly*/ class: ClassMirror; |
|
|
|
// Mirror API for class instance fields |
|
defineField(propertyKey: PropertyKey): FieldMirror; // Throws if not initializing (see Mirror.state). |
|
deleteField(propertyKey: PropertyKey): boolean; // Ignored if not initializing (see Mirror.state). |
|
hasOwnField(propertyKey: PropertyKey): boolean; |
|
getOwnField(propertyKey: PropertyKey): FieldMirror; |
|
getOwnFields(): FieldMirror[]; |
|
getOwnFieldKeys(): PropertyKey[]; |
|
|
|
// Mirror API for class instance private state |
|
defineSlot(name?: string): SlotMirror; // Throws if not initializing (see Mirror.state). |
|
} |
|
|
|
// Mirror for members (properties, fields, slots) |
|
interface MemberMirror extends Mirror { |
|
/*readonly*/ kind: "method" | "accessor" | "property" | "field" | "slot"; |
|
/*readonly*/ name: PropertyKey; |
|
/*readonly*/ owner: ObjectMirror; |
|
/*readonly*/ class: ClassMirror; // undefined if not a static, prototype, or instance class member. |
|
/*readonly*/ static: boolean; // true if static member of a class |
|
|
|
// Mirror API common to members |
|
getValue(target: any): any; // from Reflect (get) |
|
setValue(target: any, value: any): boolean; // from Reflect (set) |
|
} |
|
|
|
// Mirror for properties (class methods, accessors, etc.) |
|
interface PropertyMirror extends MemberMirror { |
|
/*readonly*/ kind: "method" | "accessor" | "property"; |
|
|
|
// Properties used during property declaration initialization. |
|
enumerable: boolean; // Set throws if not initializing (see Mirror.state). |
|
configurable: boolean; // Set throws if not initializing (see Mirror.state). |
|
|
|
// Mirror API common to properties |
|
hasProperty(target: any): boolean; // from Reflect (has) |
|
hasOwnProperty(target: any): boolean; // from ObjectConstructor |
|
} |
|
|
|
// Mirror for a data property |
|
interface DataPropertyMirror extends PropertyMirror { |
|
/*readonly*/ kind: "property"; |
|
|
|
// Properties used during data property declaration initialization. |
|
writable: boolean; // Set throws if not initializing (see Mirror.state). |
|
value: any; // Set throws if not initializing (see Mirror.state). |
|
} |
|
|
|
// Mirror for a method |
|
interface MethodMirror extends PropertyMirror { |
|
/*readonly*/ kind: "method"; |
|
/*readonly*/ length: number; |
|
/*readonly*/ generator: boolean; // true if generator method |
|
/*readonly*/ async: boolean; // true if async method |
|
|
|
// Properties used during method declaration initialization. |
|
writable: boolean; // Set throws if not initializing (see Mirror.state). |
|
value: Function; // Set throws if not initializing (see Mirror.state). |
|
|
|
// Mirror API for methods |
|
getSuperMethod(prototype?: any): MethodMirror; |
|
|
|
// Mirror API for parameters |
|
getParameters(): ParameterMirror[]; |
|
|
|
// Mirror API for functions (less "construct" and "@@hasInstance") |
|
apply(thisArg: any, argArray?: any): any; // from Function |
|
call(thisArg: any, ...argArray: any[]): any; // from Function |
|
bind(thisArg: any, ...argArray: any[]): any; // from Function |
|
} |
|
|
|
// Mirror for an accessor |
|
interface AccessorMirror extends PropertyMirror { |
|
/*readonly*/ kind: "accessor"; |
|
/*readonly*/ getMethod: MethodMirror; |
|
/*readonly*/ setMethod: MethodMirror; |
|
|
|
// Properties used during accessor declaration initialization. |
|
get: Function; // Set throws if not initializing (see Mirror.state). |
|
set: Function; // Set throws if not initializing (see Mirror.state). |
|
|
|
// Mirror API for accessors |
|
getSuperAccessor(prototype?: any): AccessorMirror; |
|
} |
|
|
|
// Mirror for an instance field |
|
interface FieldMirror extends MemberMirror { |
|
/*readonly*/ kind: "field"; |
|
|
|
// Properties used during field declaration initialization. |
|
initializer: () => any; // Set throws if not initializing (see Mirror.state). |
|
|
|
// Mirror API for fields |
|
hasField(target: any): boolean; |
|
hasOwnField(target: any): boolean; |
|
} |
|
|
|
// Mirror for a private slot |
|
interface SlotMirror extends MemberMirror { |
|
/*readonly*/ kind: "slot"; |
|
/*readonly*/ name: string; |
|
|
|
// Properties used during slot declaration initialization. |
|
initializer: () => any; // Set throws if not initializing (see Mirror.state). |
|
|
|
// Mirror API for slots |
|
hasSlot(target: any): boolean; |
|
} |
|
|
|
// Mirror for a parameter |
|
interface ParameterMirror extends Mirror { |
|
/*readonly*/ kind: "parameter"; |
|
/*readonly*/ name: string; |
|
/*readonly*/ index: number; |
|
/*readonly*/ owner: FunctionMirror | ClassMirror | MethodMirror; |
|
/*readonly*/ rest: boolean; // true if rest parameter |
|
/*readonly*/ optional: boolean; // true if parameter has initializer |
|
/*readonly*/ pattern: boolean; // true if parameter is a binding element |
|
} |