在Typescript中定义类不能获得属性

时间:2017-08-23 03:27:41

标签: typescript

当我在下面定义一个简称Class时,我认为没有比此更简单的Class

class Greeter {
  greeting: string;
  constructor(message: string) {
    this.greeting = message;
  }
}

let greeter = new Greeter("world");

但是,编译此代码时,终端将调用错误错误TS2339: Property 'greeting' does not exist on type 'Greeter'.

我不知道这个错误...

这是我的tsconfig.json

{
  "compilerOptions": {
    "strictNullChecks": false,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "jsx": "preserve",
    "noUnusedParameters": true,
    "noUnusedLocals": true,
    "target": "es6",
    "lib": [
      "dom",
      "es7"
    ]
  },
  "exclude": [
    "node_modules",
    "lib",
    "es"
  ]
}

0 个答案:

没有答案