Merge pull request #17132 from mfdeveloper/corejs-es7-reflect

[Core-js] ES7 Reflect methods based on reflect-metadata
This commit is contained in:
Paul van Brenk
2017-06-26 10:32:19 -07:00
committed by GitHub

View File

@@ -1,6 +1,6 @@
// Type definitions for core-js 0.9
// Project: https://github.com/zloirock/core-js/
// Definitions by: Ron Buckton <http://github.com/rbuckton>
// Definitions by: Ron Buckton <http://github.com/rbuckton>, Michel Felipe <http://github.com/mfdeveloper>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
@@ -50,7 +50,10 @@ declare function $for<T>(iterable: Iterable<T>): $for<T>;
// ECMAScript 7
// Modules: es7.array.includes, es7.string.at, es7.string.pad-start, es7.string.pad-end,
// es7.object.to-array, es7.object.get-own-property-descriptors, es7.regexp.escape,
// es7.map.to-json, and es7.set.to-json
// es7.map.to-json, es7.set.to-json, es7.reflect.define-metadata, es7.reflect.delete-metadata
// es7.reflect.get-metadata, es7.reflect.get-metadata-keys, es7.reflect.get-own-metadata,
// es7.reflect.get-own-metadata-keys, es7.reflect.has-metadata, es7.reflect.has-own-metadata
// es7.reflect.metadata
// #############################################################################################
interface String {
@@ -473,6 +476,202 @@ declare namespace core {
function preventExtensions(target: any): boolean;
function set(target: any, propertyKey: PropertyKey, value: any, receiver?: any): boolean;
function setPrototypeOf(target: any, proto: any): boolean;
/**
* Define a unique metadata entry on the target.
* @param metadataKey A key used to store and retrieve metadata.
* @param metadataValue A value that contains attached metadata.
* @param target The target object on which to define metadata.
* @example
*
* ### Example
*
* ```typescript
* class Example {
* }
*
* // constructor
* Reflect.defineMetadata("custom:annotation", options, Example);
*
* // decorator factory as metadata-producing annotation.
* function MyAnnotation(options): ClassDecorator {
* return target => Reflect.defineMetadata("custom:annotation", options, target);
* }
* ```
*/
function defineMetadata(metadataKey: any, metadataValue: any, target: Object, targetKey?: string | symbol): void;
/**
* Deletes the metadata entry from the target object with the provided key.
* @param metadataKey A key used to store and retrieve metadata.
* @param target The target object on which the metadata is defined.
* @returns `true` if the metadata entry was found and deleted; otherwise, false.
* @example
*
* ### Example
*
* ```typescript
* class Example {
* }
*
* // constructor
* result = Reflect.deleteMetadata("custom:annotation", Example);
* ```
*/
function deleteMetadata(metadataKey: any, target: Object, targetKey?: string | symbol): boolean;
/**
* Gets the metadata value for the provided metadata key on the target object or its prototype chain.
* @param metadataKey A key used to store and retrieve metadata.
* @param target The target object on which the metadata is defined.
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
* @example
*
* ### Example
*
* ```typescript
* class Example {
* }
*
* // constructor
* result = Reflect.getMetadata("custom:annotation", Example);
* ```
*/
function getMetadata(metadataKey: any, target: Object, targetKey?: string | symbol): any;
/**
* Gets the metadata keys defined on the target object or its prototype chain.
* @param target The target object on which the metadata is defined.
* @returns An array of unique metadata keys.
* @example
*
* ### Example
*
* ```typescript
* class Example {
* }
*
* // constructor
* result = Reflect.getMetadataKeys(Example);
* ```
*/
function getMetadataKeys(target: Object, targetKey?: string | symbol): any[];
/**
* Gets the metadata value for the provided metadata key on the target object.
* @param metadataKey A key used to store and retrieve metadata.
* @param target The target object on which the metadata is defined.
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
* @example
*
* ### Example
*
* ```typescript
* class Example {
* }
*
* // constructor
* result = Reflect.getOwnMetadata("custom:annotation", Example);
* ```
*/
function getOwnMetadata(metadataKey: any, target: Object, targetKey?: string | symbol): any;
/**
* Gets the unique metadata keys defined on the target object.
* @param target The target object on which the metadata is defined.
* @returns An array of unique metadata keys.
* @example
*
* ### Example
*
* ```typescript
* class Example {
* }
*
* // constructor
* result = Reflect.getOwnMetadataKeys(Example);
* ```
*/
function getOwnMetadataKeys(target: Object, targetKey?: string | symbol): any[];
/**
* Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
* @param metadataKey A key used to store and retrieve metadata.
* @param target The target object on which the metadata is defined.
* @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
* @example
*
* ### Example
*
* ```typescript
* class Example {
* }
*
* // constructor
* result = Reflect.hasMetadata("custom:annotation", Example);
* ```
*/
function hasMetadata(metadataKey: any, target: Object, targetKey?: string | symbol): boolean;
/**
* Gets a value indicating whether the target object has the provided metadata key defined.
* @param metadataKey A key used to store and retrieve metadata.
* @param target The target object on which the metadata is defined.
* @returns `true` if the metadata key was defined on the target object; otherwise, `false`.
* @example
*
* ### Example
*
* ```typescript
*
* class Example {
* }
*
* // constructor
* result = Reflect.hasOwnMetadata("custom:annotation", Example);
* ```
*/
function hasOwnMetadata(metadataKey: any, target: Object, targetKey?: string | symbol): boolean;
/**
* A default metadata decorator factory that can be used on a class, class member, or parameter.
* @param metadataKey The key for the metadata entry.
* @param metadataValue The value for the metadata entry.
* @returns A decorator function.
* @remarks
* If `metadataKey` is already defined for the target and target key, the
* metadataValue for that key will be overwritten.
* @example
*
* ### Example
*
* ```typescript
* // constructor
* @Reflect.metadata(key, value)
* class Example {
* }
*
* // property (on constructor, TypeScript only)
* class Example {
* @Reflect.metadata(key, value)
* static staticProperty;
* }
*
* // property (on prototype, TypeScript only)
* class Example {
* @Reflect.metadata(key, value)
* property;
* }
*
* // method (on constructor)
* class Example {
* @Reflect.metadata(key, value)
* static staticMethod() { }
* }
*
* // method (on prototype)
* class Example {
* @Reflect.metadata(key, value)
* method() { }
* }
* ```
*/
function metadata(metadataKey: any, metadataValue: any): {
(target: Function): void;
(target: Object, targetKey: string | symbol): void;
};
}
const Object: {
@@ -1991,6 +2190,42 @@ declare module "core-js/library/fn/reflect/set-prototype-of" {
const setPrototypeOf: typeof core.Reflect.setPrototypeOf;
export = setPrototypeOf;
}
declare module "core-js/library/fn/reflect/es7/define-metadata" {
const defineMetadata: typeof core.Reflect.defineMetadata;
export = defineMetadata;
}
declare module "core-js/library/fn/reflect/es7/delete-metadata" {
const deleteMetadata: typeof core.Reflect.deleteMetadata;
export = deleteMetadata;
}
declare module "core-js/library/fn/reflect/es7/get-metadata" {
const getMetadata: typeof core.Reflect.getMetadata;
export = getMetadata;
}
declare module "core-js/library/fn/reflect/es7/get-metadata-keys" {
const getMetadataKeys: typeof core.Reflect.getMetadataKeys;
export = getMetadataKeys;
}
declare module "core-js/library/fn/reflect/es7/get-own-metadata" {
const getOwnMetadata: typeof core.Reflect.getOwnMetadata;
export = getOwnMetadata;
}
declare module "core-js/library/fn/reflect/es7/get-own-metadata-keys'" {
const getOwnMetadataKeys: typeof core.Reflect.getOwnMetadataKeys;
export = getOwnMetadataKeys;
}
declare module "core-js/library/fn/reflect/es7/has-metadata'" {
const hasMetadata: typeof core.Reflect.hasMetadata;
export = hasMetadata;
}
declare module "core-js/library/fn/reflect/es7/has-own-metadata'" {
const hasOwnMetadata: typeof core.Reflect.hasOwnMetadata;
export = hasOwnMetadata;
}
declare module "core-js/library/fn/reflect/es7/metadata'" {
const metadata: typeof core.Reflect.metadata;
export = metadata;
}
declare module "core-js/library/fn/regexp" {
const RegExp: typeof core.RegExp;
export = RegExp;