Questions tagged [reflect-metadata]

83 questions
0
votes
0 answers

TypeORM not working with Lambda using SAM/esbuild: Cannot find module 'reflect-metadata'

I've a small lambda configured through SAM OrganizationPOSTFunction: Type: AWS::Serverless::Function Properties: FunctionName: OrganizationPOST CodeUri: ../src/ Handler: organization-post.lambdaHandler Timeout: 900 …
clagccs
  • 2,224
  • 2
  • 21
  • 33
0
votes
0 answers

Iterating on prototypes in typescript

I am trying to learn typescript and in my course, there is a section where my tutor is trying to create a class for login controller and I am trying to use decorators to create some kind of modular structure. Now, what is my problem? I create…
0
votes
0 answers

Can't get Reflect.metadata to work in React

I have this Typescript code: import 'reflect-metadata'; export const formatMetadataKey = Symbol("format"); export function format(formatString: string) { return Reflect.metadata(formatMetadataKey, formatString); } export function…
Adrian Rosca
  • 6,922
  • 9
  • 40
  • 57
0
votes
0 answers

How to get the decorators applied to method arguments?

I am looking for a way to get the decorators applied to each method arguments using Reflect.getMetadataKeys.This works perfect to get decorators applied to method itself but I don't know how to get to the arguments decorators. In my case I want to…
0
votes
0 answers

Getting a property type using reflect-metadata

I have a number of classes that all have a body property, e.g: class MyClass { body: { name: string, address: string, favouriteThings: Array } } I'd like to have an automated way of getting the type of the body object, so I…
Pezholio
  • 2,439
  • 5
  • 27
  • 41
0
votes
0 answers

Get param class type in NestJS cutom param decorator

I have a NestJS TS application that has an xml endpoint. I want to validate an xml body. Here's how I went with parsing xml to js object: @Injectable() export class XmlToJsInterceptor implements NestInterceptor { constructor(private parser:…
0
votes
1 answer

plainToClass to call object.method() in web worker thread

I am using angular, trying to pass an object to the web worker for the background process. the class is Article{ method1(); propertyA; } addEventListener('message', ({ data }) => { // if without plainToClass, how to call article.method1() …
Tonghua
  • 57
  • 8
0
votes
1 answer

refect-metadata "design:type" circular dependency

In this repo you can clearly see that both of the classes have metadata design:type on the properties. Only one of them though shows when I try to probe for it. Can someone explain?
SamJust
  • 101
  • 1
  • 1
  • 4
0
votes
1 answer

Access class decorator argument using reflect-metadata

Consider a class decorator with one argument: @TableName("Orders") export class Order { // ... } And the decorator defined as: import "reflect-metadata"; const classDecoratorKey = Symbol.for("custom:TableName"); export function…
Carlos Torres
  • 419
  • 2
  • 9
  • 19
0
votes
1 answer

Cannot define nor retrieve metadata on method

I'm trying to attach a metadata key-value pair to an object key (method in a TS class), but no action is actually being performed on the element. import 'reflect-metadata'; export const get = (path: string) => (target: any, key: string, desc:…
0
votes
1 answer

Typescript Decorators before class instance

Iam playing around with Typescript decorators and everything is quite good working when I have instanciated a class. With the following code, my Class-decorator gets called: import { MyClass } from "./MyClass"; const myClass = new MyClass(); But…
0
votes
0 answers

Use a custom ClassDecorator to inject a dependency in class instance

I'm writing a module for NestJS where I'd like to have a custom ClassDecorator that: Makes a class @Injectable Injects a dependency in the class instance Here is a few lines of code that illustrate what I expect: // app.module.ts @Module({ …
0
votes
1 answer

loader exception / circular reference by decorators

Question I get a circular loader exception. This is may caused by the compiler option "emitDecoratorMetadata":true. How can I fix it? Thanks for helpful replays! Introduction I have prepared a minimal project for reproducing the error. Please take a…
Barock
  • 427
  • 1
  • 4
  • 12
0
votes
1 answer

Pass object and attribute at once for reflect-metadata in TypeScript like in C#

In C# we've DataAnnotation to add meta attributes on properties. I need this functionality in TypeScript for a ldap model class. Decorators should set the LDAP attribute which is internally used in the LDAP directory export class LdapUser { …
user6643481
0
votes
1 answer

Define a decorator guard in typescript

Imagine that you have classes that implement a certain decorator: @Component class A @Component class B If you want to have a variable that holds the class itself of some of this classes, what type would it have? componentClass: typeof A | typeof…
Sergio Carneiro
  • 3,726
  • 4
  • 35
  • 51