I've been working on implementing dependency injection in TypeScript using Deno, but I've encountered a problem with the
Reflect.getMetadata('design:paramtypes', ...)
method, as it's returning an undefined
value and I'm not sure why.
Deno 1.6.0
Ubuntu 18.04.5 LTS
The Reflect file I'm using is located here: 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)) // this line is giving me undefined
Command used to execute:
$ deno run main.ts
Github repository: https://github.com/edualb/dependencyInjectionPOC
Can anyone provide assistance with this issue?