Questions tagged [reflect-metadata]
83 questions
2
votes
2 answers
Why is `this` undefined when passing a Function into Metadata and how to fix it?
I want to create an abstraction with the help of Typescript decorators and reflect-metadata. But when I invoke the function I pass into the metadata, this is undefined:
import "reflect-metadata";
const METHODS = "__methods__";
const Method = (obj:…

Florian Ludewig
- 4,338
- 11
- 71
- 137
2
votes
0 answers
Typescript - How to get all class properties with decorators from a class decorator
I want to have a class decorator that gets a list of all properties with a certain decorator and then modify the class to add some additional properties. For example:
@CheckForPropertyThings
export class FoorBar {
@PropertyThing hello:…

kbdsharp
- 21
- 2
2
votes
0 answers
How to get all properties in class, which inherits from base class, decorated with a certain decoration
I am trying to get all properties that are decorated with certain decorator. I am trying to use reflect metadata for this, but it doesn't work properly if class inherits from another class which also has decorated property.
Problem is that target in…

Makla
- 9,899
- 16
- 72
- 142
2
votes
1 answer
Typescript cannot access property type from typescript decorator. (Target is: {})
I'm currently implementing a dependency injector to use in a VUE js project.
I have created an Inject decorator and I want to be able to access a property type, I had it working yesterday but something has happened and I'm completely lost. I've…

Jack_b_321
- 848
- 8
- 22
2
votes
2 answers
How to import reflect-metadata correctly
So I have a TypeScript project I am working on and I want to make use of the reflect-metadata package. I am a little confused about the correct way of importing this. It was my understanding that this only needed to be imported once in your "main"…

Mikey Dee
- 91
- 3
- 10
2
votes
1 answer
When and how s decorator applied to the decorated classes from the @angular packages
If I use a decorator in my class the decorator is evaluated when importing the class. Here is the small example:
@NgModule({ ... })
export class BModule { ... }
Transpiled as:
var BModule = (function () {
function BModule() {
}
BModule…

Max Koretskyi
- 101,079
- 60
- 333
- 488
2
votes
1 answer
Where do I find the metadataKey values used in reflect-metadata
I'm using typescript and Angular (2.4.7)
reflect-metadata refers to magical strings, where do I find what these are, where they are defined? For example "design:type"
function Type(type) { return Reflect.metadata("design:type", type); }
function…

Brandon
- 984
- 1
- 11
- 26
2
votes
1 answer
Correct way to reference reflect-metadata or equivalent in angular app
In this plunker I'm attempting to decorate a property on MyModel with a custom annotation. Un-commenting the property with custom decorator or un-commenting import 'reflect-metadata'; and the property with inline decorator generates:
Error: Cannot…

Wilhelmina Lohan
- 2,803
- 2
- 29
- 58
1
vote
1 answer
Getting a modified type from a class marked by decorator
I have a class defined like:
class Person {
@OneToOne()
pet: Animal;
}
Is there a way to get a modified type which looks like this? (Adding {propertyKey}Id: string to properties by marking it with a decorator)
// Using generics
type…

SnowSuno
- 17
- 5
1
vote
0 answers
Why do TSyringe and reflect-metadata need to be installed as dependencies and not dev dependencies?
I recently installed TSyringe into a Node project using TypeScript. TSyringe also needs reflect-metadata.
I initially installed these packages as dev dependencies and things worked fine in my dev env/TS land. But when I ran a production build I got…

eysikal
- 579
- 1
- 6
- 13
1
vote
1 answer
Can typescript property decorators modify instance members instead of the entire class?
I want to write a sanitizer decorator which I can put on all user-input string fields. This simply replaces the standard .set(newValue) with .set( sanitize(newValue) ). However I have found the below code only works for one instance. A second…

Fred Johnson
- 2,539
- 3
- 26
- 52
1
vote
1 answer
What happens when `typeorm/browser/index.js` throws "Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' error"?
I recently came up with a new pure JS web app running on Node.js (not importing anything about TypeScript), having Next.js@12.0.10 as the framework and TypeORM@0.2.41 as the ORM layer to an Azure SQL server.
Everything works fine and I've connected…

cschenio
- 97
- 2
- 8
1
vote
0 answers
Reflect metadata design:paramtypes return an array with unfedined element
I'm trying to obtain the constructor arguments for some class but the <> get an array with a undefined element.
For the test I work with services Example2Services and ExampleService
Example2Service.ts
import { ExampleService } from…

Felipe Nuñez
- 73
- 2
- 10
1
vote
0 answers
How to detect circular dependency in Typescript
The code below has a circular dependency issue. A -> B -> A
Reproducible problem:
/a.ts
import {B} from './b';
import { Service } from './test';
@Service
export class A {
static id = 'A'
constructor(b: B) {
}
}
/b.ts
import {A} from…

TSR
- 17,242
- 27
- 93
- 197
1
vote
1 answer
Reflect-metadata: check if property has "Output()" decorator
I am writing an Angular library. An object wraps an Angular component instance, and this object has to subscribe to all subjects marked with Output decorator within the component instance.
This is what I have coded so far inside the…

Igino Boffa
- 686
- 1
- 9
- 21