typescript - 反射元数据“设计:参数类型”在 Deno 上返回未定义
问题描述
我正在尝试使用Deno在 typescript 中实现依赖注入,但是,我遇到了一个问题,Reflect.getMetadata('design:paramtypes', ...)
即返回一个undefined
值,我不明白为什么。
Deno 1.6.0
Ubuntu 18.04.5 LTS
我使用这个文件作为反映:https ://github.com/edualb/dependencyInjectionPOC/blob/main/Reflect.ts
tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"lib": ["es5", "es6", "dom"],
}
}
代码
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
用于执行的命令:
$ deno run main.ts
Github:https ://github.com/edualb/dependencyInjectionPOC
有没有人可以帮助解决这个问题?
解决方案
我已经解决了这个问题,将标志-c
/--config
放在执行命令中:
$ deno run -c tsconfig.json main.ts
推荐阅读
- java - 如何在 Java 中实现 A*?
- java - Java - 将值输入 JTextArea 后事件之间的延迟
- java - 尝试编写一个函数以在发生错误时返回 false
- raku - 在 Raku 中混合私有和公共属性和访问器
- tvos - tvOS 究竟何时清除数据?
- r - 如何在基于向量的数据框中插入一列?
- pagination - Splunk - 添加分页
- javascript - 为什么我的提示计算器代码返回 NaN?
- sql - Oracle SQL - 未来日期/雇主年龄问题
- java - 将 Java 程序连接到 MySQL 中的数据库时出现 MySQLNonTransientConnectionException