使用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:类型'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上的自动完成不正确。
答案 0 :(得分:1)
不知何故开始工作了。将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
}
也许这对某人有用。