Skip to main content

Reflect metadata

Less than 1 minutefeaturees-proposal

Reflect metadataopen in new window

Modules

Types

namespace Reflect {
  function defineMetadata(
    metadataKey: any,
    metadataValue: any,
    target: Object,
    propertyKey?: PropertyKey
  ): void;
  function getMetadata(
    metadataKey: any,
    target: Object,
    propertyKey?: PropertyKey
  ): any;
  function getOwnMetadata(
    metadataKey: any,
    target: Object,
    propertyKey?: PropertyKey
  ): any;
  function hasMetadata(
    metadataKey: any,
    target: Object,
    propertyKey?: PropertyKey
  ): boolean;
  function hasOwnMetadata(
    metadataKey: any,
    target: Object,
    propertyKey?: PropertyKey
  ): boolean;
  function deleteMetadata(
    metadataKey: any,
    target: Object,
    propertyKey?: PropertyKey
  ): boolean;
  function getMetadataKeys(
    target: Object,
    propertyKey?: PropertyKey
  ): Array<any>;
  function getOwnMetadataKeys(
    target: Object,
    propertyKey?: PropertyKey
  ): Array<any>;
  function metadata(
    metadataKey: any,
    metadataValue: any
  ): (target: Object, targetKey: string | symbol) => void;
}

Entry points

core-js/proposals/reflect-metadata
core-js(-pure)/full/reflect/define-metadata
core-js(-pure)/full/reflect/delete-metadata
core-js(-pure)/full/reflect/get-metadata
core-js(-pure)/full/reflect/get-metadata-keys
core-js(-pure)/full/reflect/get-own-metadata
core-js(-pure)/full/reflect/get-own-metadata-keys
core-js(-pure)/full/reflect/has-metadata
core-js(-pure)/full/reflect/has-own-metadata
core-js(-pure)/full/reflect/metadata

Example

Exampleopen in new window:

let object = {};
Reflect.defineMetadata("foo", "bar", object);
Reflect.ownKeys(object); // => []
Reflect.getOwnMetadataKeys(object); // => ['foo']
Reflect.getOwnMetadata("foo", object); // => 'bar'