我正在使用oclif构建一个CLI实用程序,用类型记录编写它。
在vscode中,所有生成的命令文件都给出了一个错误:
如果不引用'../../../../../../Projects/bag-man/tmp/mynewcli/node_modules/@oclif/parser/lib/flags'.,就不能命名推断类型的“标志”。这可能是不可携带的。类型注释是必要的。
特别令人沮丧的是,在某些文件中,它对同一个实例重复错误4次(即整个文件中只有一个红色下划线,但"Problems“视图列出了4次相同的问题)。
这是一个文件,显示它4次-这正是oclif为一个命令文件生成的。问题出现在flags的第12行。
import {Command, flags} from '@oclif/command'
export default class Hello extends Command {
static description = 'describe the command here'
static examples = [
`$ mynewcli hello
hello world from ./src/hello.ts!
`,
]
static flags = {
help: flags.help({char: 'h'}),
// flag with a value (-n, --name=VALUE)
name: flags.string({char: 'n', description: 'name to print'}),
// flag with no value (-f, --force)
force: flags.boolean({char: 'f'}),
}
static args = [{name: 'file'}]
async run() {
const {args, flags} = this.parse(Hello)
const name = flags.name ?? 'world'
this.log(`hello ${name} from ./src/commands/hello.ts`)
if (args.file && flags.force) {
this.log(`you input --force and --file: ${args.file}`)
}
}
}知道我需要修改什么,无论是在代码中还是在vscode linter设置中,来解决这个问题吗?
发布于 2021-09-07 09:19:08
我还没有了解原因,但是在您的"declaration": false中设置tsconfig.json可以解决这个问题。
发布于 2021-11-08 22:43:04
我通过将类型添加到flags字段来解决这个问题。例如:
static flags : flags.Input<any> = {
// your flags...
}https://stackoverflow.com/questions/68914671
复制相似问题