Vue + Typescript - 无效类型

Vue + Typescript - invalid types

使用 typescript 2.8.3、ts-loader 3.5.0(由于使用了 webpack 2)和 vue 2.5.16 尝试在 SFC 中定义组件时出现错误,如下所示:

<script lang="ts">
  import Vue from 'vue'

  export default Vue.extend({
     name: 'TestComponent',

     props: {
       options: {
          type: Array,
          default: () => [],
       }
     },

     computed: {
       getOptions() {
          return this.options
       },
     }
  })
</script>

这是错误:

TS2339: Property 'options' does not exist on type 'ComponentOptions, DefaultMethods, DefaultComputed, PropsDefinition

这是tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "noImplicitAny": false,
    "baseUrl": ".",
    "allowJs": true,
    "paths": {
      "test/*": ["test/*"]
    },
    "lib": ["dom", "es2016"],
    "types": ["node", "jest"]
  },
  "include": ["resources/assets/js/**/*.ts", "resources/assets/js/**/*.vue"],
  "exclude": ["node_modules"]
}

有什么想法吗?如果我设置 "noImplicityThis" 工作正常:false 但 VSCode 上的自动完成不正确。

不知何故开始工作。将 tsconfig.json 更改为以下内容:

{
  "compilerOptions": {
    "target": "es5",
    "module": "esnext",
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitAny": false,
    "jsx": "preserve",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "allowJs": true,
    "lib": ["dom", "esnext"],
    "types": ["node", "jest"]
  },
  "include": ["resources/assets/js/**/*.ts", "resources/assets/js/**/*.vue"],
  "exclude": ["node_modules"]
}

和vue.d.ts到:

declare module '*.vue' {
  import Vue from 'vue'
  export default Vue
}

也许对某人有用。