如何使用vue js @Component与typescript 2.6.1?

时间:2017-11-03 16:41:04

标签: vuejs2 typescript2.0 tsconfig

我创建了一个小组件:

Sub Macro2()
' Macro Macro2
' Macro Recorded 11/3/17 by me.
    ApplyReport Name:="Lauren"
    DocumentExport fileName:="X:\Schedule\Schedules\Lauren.pdf"
End Sub

我可以使用typescript@2.5.3

毫无问题地编译项目

但如果我尝试使用typescript@2.6.1,我就会遇到这样的错误:

[at-loader]中的错误./src/components/home/home.ts:8:2

import Vue from 'vue';
import Component from 'vue-class-component';
import { Inject, Model, Prop, Watch } from 'vue-property-decorator';

@Component({
    template: require('./home.html'),
})
export class HomeComponent extends Vue {
    name: string = 'User';
}

据我所知,问题出在以下三行代码中:

TS2345: Argument of type 'typeof HomeComponent' is not assignable to parameter of type 'VueClass<Vue>'.
Type 'typeof HomeComponent' is not assignable to type 'new (...args: any[]) => Vue'.
  Type 'HomeComponent' is not assignable to type 'Vue'.
    Types of property '$options' are incompatible.
      Type 'ComponentOptions<HomeComponent, DefaultData<HomeComponent>,
      DefaultMethods<HomeComponent>, Defaul...' is not assignable to type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Rec...'.
      Type 'HomeComponent' is not assignable to type 'Vue'.

我试图以这种方式替换:

@Component({
    template: require('./home.html'),
})

但是我收到了错误:

@Component

所以我试图完全删除3行@Component

显然,代码已编译

[at-loader]好的,0.97秒

但是程序无法正常工作

ERROR in [at-loader] ./src/components/home/home.ts:7:1
TS1238: Unable to resolve signature of class decorator when called as an expression.
Type '<VC extends VueClass<Vue>>(target: VC) => VC' is not assignable to type 'typeof HomeComponent'.
  Property 'extend' is missing in type '<VC extends VueClass<Vue>>(target: VC) => VC'.

如何使用vue js @Component与typescript 2.6.1?

1 个答案:

答案 0 :(得分:9)

我遇到了同样的问题,我能够删除该错误的方法是在我的tsconfig.json中添加

"strictFunctionTypes": false

这是functions are checked

的变化