复现
通用 Array 构造函数没有描述数组元素的解析器:
src/app.module.ts
import { CommandMajor, FuncModule, Handler, SubOptions, run } from 'func'
@CommandMajor()
@SubOptions([{ name: 'tag', type: Array }])
class BuildCommand {
@Handler()
run() {}
}
@FuncModule({ commands: [BuildCommand] })
class AppModule {}
run(AppModule)这个错误是什么
func 需要为每个重复值确定具体的解析器。单独使用 Array 无法识别元素类型,因此参数解析开始前,注册流程就会停止。错误中的 details.option 和 details.handler 会指出对应声明。
如何修复
重复字符串选项应使用 [String]:
src/build.command.ts
@SubOptions([{ name: 'tag', type: [String] }])
class BuildCommand {}对于类字段,优先使用 @ArrayValue(),它会自动提供受支持的解析器。