【问题标题】:Suppress declaration expected ts(1146) with graphql使用 graphql 抑制声明预期的 ts(1146)
【发布时间】:2021-08-12 00:29:39
【问题描述】:

在对象中的函数上使用装饰器时出现以下错误

这是带有装饰器的对象:

export default {
  Query: {
    @query
    containerById: async (scope, { id }, context) => {
      return context.loaders.containerLoader.getContainerById.load(id);
    },
  }
};

我试图抑制这个错误,但我无法做到。

我能够做到的唯一方法是将以下行添加到.vscode/settings.json

"typescript.validate.enable": false

这显然是一个糟糕的解决方案,因为它禁用了我不想要的所有打字稿验证。

这是我的tsconfig.json 文件:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    "allowJs": true,
    "sourceMap": true,
    "outDir": "./lib",
    "strict": true,
    "noImplicitAny": false,
    "moduleResolution": "node",
    "baseUrl": ".",
    "paths": {
      "/*": ["./src/*"]
    },
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

【问题讨论】:

    标签: typescript visual-studio-code graphql


    【解决方案1】:

    VS Code 使用 TypeScript 插件进行这些验证(您可以看到它,因为错误的名称是 ts(1146)

    目前在 GitHub 上的 TypeScript 存储库中有一个 Open Issue,要求支持在对象内的函数上使用装饰器。这将消除 VS Code 中的 IntelliSense 错误。

    如果您喜欢这个功能,也许投票支持 GitHub 问题可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-01-19
      • 1970-01-01
      • 2019-12-17
      • 2021-07-29
      • 2015-07-02
      • 2022-11-14
      相关资源
      最近更新 更多