typescript - 在vscode中使用oclif,如何解决 "The inferred type of ' flags'无法在没有引用的情况下命名...”问题?

标签 typescript visual-studio-code oclif

我正在使用 ocif 构建一个 CLI 实用程序,并用 Typescript 编写。

在 vscode 中,所有生成的命令文件都给我一个错误,提示

The inferred type of 'flags' cannot be named without a reference to '../../../../../../Projects/bag-man/tmp/mynewcli/node_modules/@oclif/parser/lib/flags'. This is likely not portable. A type annotation is necessary.

额外令人沮丧的部分是,在某些文件中,它对同一实例重复错误 4 次(即整个文件中只有一条红色下划线,但“问题” View 列出了相同的问题 4 次。)

这是显示它 4 次的文件之一 - 这正是 ocif 为命令文件生成的内容。该问题出现在 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 设置中修改什么来解决这个问题吗?

最佳答案

我还没有研究原因,但在 tsconfig.json 中设置 "declaration": false 解决了这个问题。

关于typescript - 在vscode中使用oclif,如何解决 "The inferred type of ' flags'无法在没有引用的情况下命名...”问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68914671/

相关文章:

node.js - 如何在 oclif 中使用 cli-ux 提示测试用户输入?

typescript - 获取或阅读数据分类术语库 Sharepoint

go - vs 代码调试 go 测试未传递标志

node.js - Ocif 动态自动完成与 http 调用

Flutter 自动导入扩展文件不起作用

angular - 在 Angular 6 中添加 http header

database - 服务器分页 : Typescript Save GET method data to number

typescript :接口(interface)函数声明中 => 和 : 的区别

angular - 在 IIS 中托管 Angular 4 应用程序后出现 HTTP 错误 500.19 内部服务器错误