From 4be31e2b04fd52cfb27a8d465072788a4d7f0c5f Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Thu, 18 Feb 2016 08:52:13 +0200 Subject: [PATCH] Add global __metadata function When `emitDecoratorMetadata` compiler option is set to true in `tsconfig.json`, TypeScript generates some calls to `__metadata` function. By default in our NativeScript TypeScript projects the `noEmitHelpers` option is set to true, so TypeScript compiler does not generate the `__metadata` function. So the application crashes at runtime. Add the missing method, so we can have both `noEmitHelpers` and `emitDecoratorMetadata` set to true in `tsconfig.json`. --- globals/globals.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/globals/globals.ts b/globals/globals.ts index 2257f8b16..58fb5837c 100644 --- a/globals/globals.ts +++ b/globals/globals.ts @@ -119,6 +119,14 @@ if (typeof global.__decorate !== "function") { } } +if (typeof global.__metadata !== "function") { + global.__metadata = function (k, v) { + if (typeof global.Reflect === "object" && typeof global.Reflect.metadata === "function") { + return global.Reflect.metadata(k, v); + } + }; +} + export function Deprecated(target: Object, key?: string | symbol, descriptor?: any) { if (descriptor) { var originalMethod = descriptor.value;