EN
← 错误索引

F_SYSTEM_INVALID_ARGS_DECORATOR_TARGET

@Args 装饰目标无效

@Args 被用于构造函数,而不是 Command 的 Handler 参数。

更新于

复现

@Args() 依赖已经选中的 Command invocation,因此不能注入构造函数:

src/deploy.command.ts
import { Args, Command, Handler } from 'func'
import type { Args as CommandArgs } from 'func'

@Command('deploy')
class DeployCommand {
  constructor(@Args() args: CommandArgs) {}

  @Handler()
  run() {}
}

如何修复

把参数移动到 @Handler() method:

src/deploy.command.ts
class DeployCommand {
  @Handler()
  run(@Args() args: CommandArgs) {
    console.log(args.inputs)
  }
}

构造函数需要调用上下文时可以注入 Contextdetails.targetdetails.index 分别指出错误 class 与参数位置。