jeudi 10 décembre 2020

Reflection metadata 'design:paramtypes' returning undefined on Deno

I am trying to implement a dependency injection in typescript using Deno, however, I have been getting a problem with Reflect.getMetadata('design:paramtypes', ...) that is returning an undefined value and I don't understand why.

Deno 1.6.0
Ubuntu 18.04.5 LTS

I am using This file as Reflect: https://github.com/edualb/dependencyInjectionPOC/blob/main/Reflect.ts

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "lib": ["es5", "es6", "dom"],
  }
}

Code

decorator.ts

export interface Type<T> {
    new(...args: any[]): T;
}

export function Injectable(): (target: Type<any>) => void {
    return (target: Type<any>) => {}
}

service2.ts

import { Injectable } from './decorator.ts';

@Injectable()
export class Service2 {
    constructor() {}
}

service.ts

import { Injectable } from './decorator.ts';
import { Service2 } from './service2.ts';

@Injectable()
export class Service {
    constructor(private s2: Service2) {}
}

main.ts

import { Reflect } from './Reflect.ts';
import { Service } from './service.ts';

console.log(Reflect.getMetadata('design:paramtypes', Service)) // here is returning undefined

Command using to execute:

$ deno run main.ts

Github: https://github.com/edualb/dependencyInjectionPOC

Would have anyone can help with this issue?





Aucun commentaire:

Enregistrer un commentaire