【问题标题】:TypeScript Decorators error in WebStormWebStorm 中的 TypeScript 装饰器错误
【发布时间】:2017-05-14 06:24:31
【问题描述】:

首先 - 不是 Using of TypeScript decorators caused errors 的重复项,因为我在 tsconfing.json 中使用了 "experimentalDecorators" : true 并且没有帮助,这可能是 WebStorm 问题。

所以我使用 Mobx 并尝试使用它的装饰器,我得到了这个错误(这是直截了当的):

问题是,我在项目根目录下的 tsconfig 已经有了这个,这是我的 tsconfig 文件:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "outDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": false,
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es5",
    "jsx": "react",
    "lib": ["dom", "es2016"],
    "types": ["mocha", "chai", "node", "protractor"]
  },
  "include": [
    "./test/matchers/custom.matchers.d.ts",
    "./test/**/*.ts"
  ],
  "files": [
    "./src/external-types.d.ts",
    "./src/app.tsx"
  ]
}

我错过了什么?为什么 WebStorm 总是在每个装饰器上显示这个错误?

【问题讨论】:

  • 你的form-store.ts文件在./test/目录下吗?使用这两个文件并包含在 tsconfig.json 中是否有效?文档似乎暗示它是其中之一:typescriptlang.org/docs/handbook/tsconfig-json.html
  • @JBNizet 它不在测试目录下,一般其他一切正常,只是装饰器有问题
  • 那么您的 tsconfig.json 不适用于此文件,因为它不包含在内。
  • @JBNizet 你是对的......我错过了,请发布答案,以便我接受并投票:)

标签: typescript webstorm


【解决方案1】:

您的 tsconfig.json 不适用于此文件,因为它不在 ./test 下,而您的 tsconfig.json 有

"include": [
  "./test/matchers/custom.matchers.d.ts",
  "./test/**/*.ts"
]

【讨论】:

    【解决方案2】:

    你需要括号,不是@observable,是@observable(),另一个也一样

    【讨论】:

      猜你喜欢
      • 2016-03-27
      • 1970-01-01
      • 2021-05-11
      • 2017-11-15
      • 2018-06-08
      • 2015-09-02
      • 1970-01-01
      • 2011-04-18
      • 1970-01-01
      相关资源
      最近更新 更多