Reflect.d.ts 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. /*! *****************************************************************************
  2. Copyright (C) Microsoft. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  4. this file except in compliance with the License. You may obtain a copy of the
  5. License at http://www.apache.org/licenses/LICENSE-2.0
  6. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  7. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  8. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  9. MERCHANTABLITY OR NON-INFRINGEMENT.
  10. See the Apache Version 2.0 License for specific language governing permissions
  11. and limitations under the License.
  12. ***************************************************************************** */
  13. // NOTE: This file is obsolete and may be removed in a later release.
  14. // For CommonJS/AMD/UMD/SystemJS declarations please use 'index.d.ts'.
  15. // For standalone browser declarations, please use 'standalone.d.ts'.
  16. declare module "reflect-metadata" {
  17. // The "reflect-metadata" module has no imports or exports, but can be used by modules to load the polyfill.
  18. }
  19. declare namespace Reflect {
  20. /**
  21. * Applies a set of decorators to a target object.
  22. * @param decorators An array of decorators.
  23. * @param target The target object.
  24. * @returns The result of applying the provided decorators.
  25. * @remarks Decorators are applied in reverse order of their positions in the array.
  26. * @example
  27. *
  28. * class Example { }
  29. *
  30. * // constructor
  31. * Example = Reflect.decorate(decoratorsArray, Example);
  32. *
  33. */
  34. function decorate(decorators: ClassDecorator[], target: Function): Function;
  35. /**
  36. * Applies a set of decorators to a property of a target object.
  37. * @param decorators An array of decorators.
  38. * @param target The target object.
  39. * @param targetKey The property key to decorate.
  40. * @param descriptor A property descriptor
  41. * @remarks Decorators are applied in reverse order.
  42. * @example
  43. *
  44. * class Example {
  45. * // property declarations are not part of ES6, though they are valid in TypeScript:
  46. * // static staticProperty;
  47. * // property;
  48. *
  49. * static staticMethod() { }
  50. * method() { }
  51. * }
  52. *
  53. * // property (on constructor)
  54. * Reflect.decorate(decoratorsArray, Example, "staticProperty");
  55. *
  56. * // property (on prototype)
  57. * Reflect.decorate(decoratorsArray, Example.prototype, "property");
  58. *
  59. * // method (on constructor)
  60. * Object.defineProperty(Example, "staticMethod",
  61. * Reflect.decorate(decoratorsArray, Example, "staticMethod",
  62. * Object.getOwnPropertyDescriptor(Example, "staticMethod")));
  63. *
  64. * // method (on prototype)
  65. * Object.defineProperty(Example.prototype, "method",
  66. * Reflect.decorate(decoratorsArray, Example.prototype, "method",
  67. * Object.getOwnPropertyDescriptor(Example.prototype, "method")));
  68. *
  69. */
  70. function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: Object, targetKey: string | symbol, descriptor?: PropertyDescriptor): PropertyDescriptor;
  71. /**
  72. * A default metadata decorator factory that can be used on a class, class member, or parameter.
  73. * @param metadataKey The key for the metadata entry.
  74. * @param metadataValue The value for the metadata entry.
  75. * @returns A decorator function.
  76. * @remarks
  77. * If `metadataKey` is already defined for the target and target key, the
  78. * metadataValue for that key will be overwritten.
  79. * @example
  80. *
  81. * // constructor
  82. * @Reflect.metadata(key, value)
  83. * class Example {
  84. * }
  85. *
  86. * // property (on constructor, TypeScript only)
  87. * class Example {
  88. * @Reflect.metadata(key, value)
  89. * static staticProperty;
  90. * }
  91. *
  92. * // property (on prototype, TypeScript only)
  93. * class Example {
  94. * @Reflect.metadata(key, value)
  95. * property;
  96. * }
  97. *
  98. * // method (on constructor)
  99. * class Example {
  100. * @Reflect.metadata(key, value)
  101. * static staticMethod() { }
  102. * }
  103. *
  104. * // method (on prototype)
  105. * class Example {
  106. * @Reflect.metadata(key, value)
  107. * method() { }
  108. * }
  109. *
  110. */
  111. function metadata(metadataKey: any, metadataValue: any): {
  112. (target: Function): void;
  113. (target: Object, targetKey: string | symbol): void;
  114. };
  115. /**
  116. * Define a unique metadata entry on the target.
  117. * @param metadataKey A key used to store and retrieve metadata.
  118. * @param metadataValue A value that contains attached metadata.
  119. * @param target The target object on which to define metadata.
  120. * @example
  121. *
  122. * class Example {
  123. * }
  124. *
  125. * // constructor
  126. * Reflect.defineMetadata("custom:annotation", options, Example);
  127. *
  128. * // decorator factory as metadata-producing annotation.
  129. * function MyAnnotation(options): ClassDecorator {
  130. * return target => Reflect.defineMetadata("custom:annotation", options, target);
  131. * }
  132. *
  133. */
  134. function defineMetadata(metadataKey: any, metadataValue: any, target: Object): void;
  135. /**
  136. * Define a unique metadata entry on the target.
  137. * @param metadataKey A key used to store and retrieve metadata.
  138. * @param metadataValue A value that contains attached metadata.
  139. * @param target The target object on which to define metadata.
  140. * @param targetKey The property key for the target.
  141. * @example
  142. *
  143. * class Example {
  144. * // property declarations are not part of ES6, though they are valid in TypeScript:
  145. * // static staticProperty;
  146. * // property;
  147. *
  148. * static staticMethod(p) { }
  149. * method(p) { }
  150. * }
  151. *
  152. * // property (on constructor)
  153. * Reflect.defineMetadata("custom:annotation", Number, Example, "staticProperty");
  154. *
  155. * // property (on prototype)
  156. * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "property");
  157. *
  158. * // method (on constructor)
  159. * Reflect.defineMetadata("custom:annotation", Number, Example, "staticMethod");
  160. *
  161. * // method (on prototype)
  162. * Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "method");
  163. *
  164. * // decorator factory as metadata-producing annotation.
  165. * function MyAnnotation(options): PropertyDecorator {
  166. * return (target, key) => Reflect.defineMetadata("custom:annotation", options, target, key);
  167. * }
  168. *
  169. */
  170. function defineMetadata(metadataKey: any, metadataValue: any, target: Object, targetKey: string | symbol): void;
  171. /**
  172. * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
  173. * @param metadataKey A key used to store and retrieve metadata.
  174. * @param target The target object on which the metadata is defined.
  175. * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
  176. * @example
  177. *
  178. * class Example {
  179. * }
  180. *
  181. * // constructor
  182. * result = Reflect.hasMetadata("custom:annotation", Example);
  183. *
  184. */
  185. function hasMetadata(metadataKey: any, target: Object): boolean;
  186. /**
  187. * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
  188. * @param metadataKey A key used to store and retrieve metadata.
  189. * @param target The target object on which the metadata is defined.
  190. * @param targetKey The property key for the target.
  191. * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
  192. * @example
  193. *
  194. * class Example {
  195. * // property declarations are not part of ES6, though they are valid in TypeScript:
  196. * // static staticProperty;
  197. * // property;
  198. *
  199. * static staticMethod(p) { }
  200. * method(p) { }
  201. * }
  202. *
  203. * // property (on constructor)
  204. * result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty");
  205. *
  206. * // property (on prototype)
  207. * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property");
  208. *
  209. * // method (on constructor)
  210. * result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod");
  211. *
  212. * // method (on prototype)
  213. * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method");
  214. *
  215. */
  216. function hasMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean;
  217. /**
  218. * Gets a value indicating whether the target object has the provided metadata key defined.
  219. * @param metadataKey A key used to store and retrieve metadata.
  220. * @param target The target object on which the metadata is defined.
  221. * @returns `true` if the metadata key was defined on the target object; otherwise, `false`.
  222. * @example
  223. *
  224. * class Example {
  225. * }
  226. *
  227. * // constructor
  228. * result = Reflect.hasOwnMetadata("custom:annotation", Example);
  229. *
  230. */
  231. function hasOwnMetadata(metadataKey: any, target: Object): boolean;
  232. /**
  233. * Gets a value indicating whether the target object has the provided metadata key defined.
  234. * @param metadataKey A key used to store and retrieve metadata.
  235. * @param target The target object on which the metadata is defined.
  236. * @param targetKey The property key for the target.
  237. * @returns `true` if the metadata key was defined on the target object; otherwise, `false`.
  238. * @example
  239. *
  240. * class Example {
  241. * // property declarations are not part of ES6, though they are valid in TypeScript:
  242. * // static staticProperty;
  243. * // property;
  244. *
  245. * static staticMethod(p) { }
  246. * method(p) { }
  247. * }
  248. *
  249. * // property (on constructor)
  250. * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty");
  251. *
  252. * // property (on prototype)
  253. * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property");
  254. *
  255. * // method (on constructor)
  256. * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod");
  257. *
  258. * // method (on prototype)
  259. * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method");
  260. *
  261. */
  262. function hasOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean;
  263. /**
  264. * Gets the metadata value for the provided metadata key on the target object or its prototype chain.
  265. * @param metadataKey A key used to store and retrieve metadata.
  266. * @param target The target object on which the metadata is defined.
  267. * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
  268. * @example
  269. *
  270. * class Example {
  271. * }
  272. *
  273. * // constructor
  274. * result = Reflect.getMetadata("custom:annotation", Example);
  275. *
  276. */
  277. function getMetadata(metadataKey: any, target: Object): any;
  278. /**
  279. * Gets the metadata value for the provided metadata key on the target object or its prototype chain.
  280. * @param metadataKey A key used to store and retrieve metadata.
  281. * @param target The target object on which the metadata is defined.
  282. * @param targetKey The property key for the target.
  283. * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
  284. * @example
  285. *
  286. * class Example {
  287. * // property declarations are not part of ES6, though they are valid in TypeScript:
  288. * // static staticProperty;
  289. * // property;
  290. *
  291. * static staticMethod(p) { }
  292. * method(p) { }
  293. * }
  294. *
  295. * // property (on constructor)
  296. * result = Reflect.getMetadata("custom:annotation", Example, "staticProperty");
  297. *
  298. * // property (on prototype)
  299. * result = Reflect.getMetadata("custom:annotation", Example.prototype, "property");
  300. *
  301. * // method (on constructor)
  302. * result = Reflect.getMetadata("custom:annotation", Example, "staticMethod");
  303. *
  304. * // method (on prototype)
  305. * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method");
  306. *
  307. */
  308. function getMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any;
  309. /**
  310. * Gets the metadata value for the provided metadata key on the target object.
  311. * @param metadataKey A key used to store and retrieve metadata.
  312. * @param target The target object on which the metadata is defined.
  313. * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
  314. * @example
  315. *
  316. * class Example {
  317. * }
  318. *
  319. * // constructor
  320. * result = Reflect.getOwnMetadata("custom:annotation", Example);
  321. *
  322. */
  323. function getOwnMetadata(metadataKey: any, target: Object): any;
  324. /**
  325. * Gets the metadata value for the provided metadata key on the target object.
  326. * @param metadataKey A key used to store and retrieve metadata.
  327. * @param target The target object on which the metadata is defined.
  328. * @param targetKey The property key for the target.
  329. * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
  330. * @example
  331. *
  332. * class Example {
  333. * // property declarations are not part of ES6, though they are valid in TypeScript:
  334. * // static staticProperty;
  335. * // property;
  336. *
  337. * static staticMethod(p) { }
  338. * method(p) { }
  339. * }
  340. *
  341. * // property (on constructor)
  342. * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty");
  343. *
  344. * // property (on prototype)
  345. * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property");
  346. *
  347. * // method (on constructor)
  348. * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod");
  349. *
  350. * // method (on prototype)
  351. * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method");
  352. *
  353. */
  354. function getOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any;
  355. /**
  356. * Gets the metadata keys defined on the target object or its prototype chain.
  357. * @param target The target object on which the metadata is defined.
  358. * @returns An array of unique metadata keys.
  359. * @example
  360. *
  361. * class Example {
  362. * }
  363. *
  364. * // constructor
  365. * result = Reflect.getMetadataKeys(Example);
  366. *
  367. */
  368. function getMetadataKeys(target: Object): any[];
  369. /**
  370. * Gets the metadata keys defined on the target object or its prototype chain.
  371. * @param target The target object on which the metadata is defined.
  372. * @param targetKey The property key for the target.
  373. * @returns An array of unique metadata keys.
  374. * @example
  375. *
  376. * class Example {
  377. * // property declarations are not part of ES6, though they are valid in TypeScript:
  378. * // static staticProperty;
  379. * // property;
  380. *
  381. * static staticMethod(p) { }
  382. * method(p) { }
  383. * }
  384. *
  385. * // property (on constructor)
  386. * result = Reflect.getMetadataKeys(Example, "staticProperty");
  387. *
  388. * // property (on prototype)
  389. * result = Reflect.getMetadataKeys(Example.prototype, "property");
  390. *
  391. * // method (on constructor)
  392. * result = Reflect.getMetadataKeys(Example, "staticMethod");
  393. *
  394. * // method (on prototype)
  395. * result = Reflect.getMetadataKeys(Example.prototype, "method");
  396. *
  397. */
  398. function getMetadataKeys(target: Object, targetKey: string | symbol): any[];
  399. /**
  400. * Gets the unique metadata keys defined on the target object.
  401. * @param target The target object on which the metadata is defined.
  402. * @returns An array of unique metadata keys.
  403. * @example
  404. *
  405. * class Example {
  406. * }
  407. *
  408. * // constructor
  409. * result = Reflect.getOwnMetadataKeys(Example);
  410. *
  411. */
  412. function getOwnMetadataKeys(target: Object): any[];
  413. /**
  414. * Gets the unique metadata keys defined on the target object.
  415. * @param target The target object on which the metadata is defined.
  416. * @param targetKey The property key for the target.
  417. * @returns An array of unique metadata keys.
  418. * @example
  419. *
  420. * class Example {
  421. * // property declarations are not part of ES6, though they are valid in TypeScript:
  422. * // static staticProperty;
  423. * // property;
  424. *
  425. * static staticMethod(p) { }
  426. * method(p) { }
  427. * }
  428. *
  429. * // property (on constructor)
  430. * result = Reflect.getOwnMetadataKeys(Example, "staticProperty");
  431. *
  432. * // property (on prototype)
  433. * result = Reflect.getOwnMetadataKeys(Example.prototype, "property");
  434. *
  435. * // method (on constructor)
  436. * result = Reflect.getOwnMetadataKeys(Example, "staticMethod");
  437. *
  438. * // method (on prototype)
  439. * result = Reflect.getOwnMetadataKeys(Example.prototype, "method");
  440. *
  441. */
  442. function getOwnMetadataKeys(target: Object, targetKey: string | symbol): any[];
  443. /**
  444. * Deletes the metadata entry from the target object with the provided key.
  445. * @param metadataKey A key used to store and retrieve metadata.
  446. * @param target The target object on which the metadata is defined.
  447. * @returns `true` if the metadata entry was found and deleted; otherwise, false.
  448. * @example
  449. *
  450. * class Example {
  451. * }
  452. *
  453. * // constructor
  454. * result = Reflect.deleteMetadata("custom:annotation", Example);
  455. *
  456. */
  457. function deleteMetadata(metadataKey: any, target: Object): boolean;
  458. /**
  459. * Deletes the metadata entry from the target object with the provided key.
  460. * @param metadataKey A key used to store and retrieve metadata.
  461. * @param target The target object on which the metadata is defined.
  462. * @param targetKey The property key for the target.
  463. * @returns `true` if the metadata entry was found and deleted; otherwise, false.
  464. * @example
  465. *
  466. * class Example {
  467. * // property declarations are not part of ES6, though they are valid in TypeScript:
  468. * // static staticProperty;
  469. * // property;
  470. *
  471. * static staticMethod(p) { }
  472. * method(p) { }
  473. * }
  474. *
  475. * // property (on constructor)
  476. * result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty");
  477. *
  478. * // property (on prototype)
  479. * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property");
  480. *
  481. * // method (on constructor)
  482. * result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod");
  483. *
  484. * // method (on prototype)
  485. * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method");
  486. *
  487. */
  488. function deleteMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean;
  489. }