Suppress declaration expected ts(1146) with graphql

Viewed 126

I have the following error when using decorator on function in object enter image description here

This is the object with the decorator:

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

I tried to suppress this error but I am unable to.

The only way I was able to is by adding the below line to .vscode/settings.json

"typescript.validate.enable": false

This obviously is a bad solution as it disables all the typescript validation which is not what I want.

This is my tsconfig.json file:

{
  "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"]
}
1 Answers

VS Code uses the TypeScript plugin for these validations (you can see it because the name of the error is ts(1146).

There is currently an Open Issue on the TypeScript repository on GitHub asking for the possibility to support using decorators on functions within objects. This will remove the IntelliSense errors in VS Code.

If you would like this feature, perhaps voting up the GitHub issue might help.

Related