vue2 typescript vue-i18n 类型报错 TS2769: No overload matches this call.‘i18n‘ does not exist in type...

ERROR in src/main.ts:51:5
TS2769: No overload matches this call.
  Overload 1 of 3, '(options?: ThisTypedComponentOptionsWithArrayProps<ExtractComputedReturns<{}> & Record<never, any> & Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<...>> & ShallowUnwrapRef<...> & Vue<...>, ... 6 more ..., ComponentOptionsMixin>): CombinedVueInstance<...>', gave the following error.
    Argument of type '{ i18n: any; store: Store<any>; }' is not assignable to parameter of type 'ThisTypedComponentOptionsWithArrayProps<ExtractComputedReturns<{}> & Record<never, any> & Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<...>> & ShallowUnwrapRef<...> & Vue<...>, ... 6 more ..., ComponentOptionsMixin>'.
      Object literal may only specify known properties, and 'i18n' does not exist in type 'ThisTypedComponentOptionsWithArrayProps<ExtractComputedReturns<{}> & Record<never, any> & Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<...>> & ShallowUnwrapRef<...> & Vue<...>, ... 6 more ..., ComponentOptionsMixin>'.
  Overload 2 of 3, '(options?: ThisTypedComponentOptionsWithRecordProps<ExtractComputedReturns<{}> & Record<never, any> & Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<...>> & ShallowUnwrapRef<...> & Vue<...>, ... 6 more ..., ComponentOptionsMixin>): CombinedVueInstance<...>', gave the following error.
    Argument of type '{ i18n: any; store: Store<any>; }' is not assignable to parameter of type 'ThisTypedComponentOptionsWithRecordProps<ExtractComputedReturns<{}> & Record<never, any> & Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<...>> & ShallowUnwrapRef<...> & Vue<...>, ... 6 more ..., ComponentOptionsMixin>'.
      Object literal may only specify known properties, and 'i18n' does not exist in type 'ThisTypedComponentOptionsWithRecordProps<ExtractComputedReturns<{}> & Record<never, any> & Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<...>> & ShallowUnwrapRef<...> & Vue<...>, ... 6 more ..., ComponentOptionsMixin>'.
  Overload 3 of 3, '(options?: ComponentOptions<ExtractComputedReturns<{}> & Record<never, any> & Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<...>> & ShallowUnwrapRef<...> & Vue<...>, ... 7 more ..., ComponentOptionsMixin>): CombinedVueInstance<...>', gave the following error.
    Argument of type '{ i18n: any; store: Store<any>; }' is not assignable to parameter of type 'ComponentOptions<ExtractComputedReturns<{}> & Record<never, any> & Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<...>> & ShallowUnwrapRef<...> & Vue<...>, ... 7 more ..., ComponentOptionsMixin>'.
      Object literal may only specify known properties, and 'i18n' does not exist in type 'ComponentOptions<ExtractComputedReturns<{}> & Record<never, any> & Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<...>> & ShallowUnwrapRef<...> & Vue<...>, ... 7 more ..., ComponentOptionsMixin>'.
    49 |
    50 | const app = new App({
  > 51 |     i18n,
       |     ^^^^
    52 |     store,
    53 | });
    54 |

最终发现是依赖node_modules/vue-i18n/types类型未引入!

修改tsconfig.json配置,添加vue-i18n/types:

tsconfig.json · TypeScript中文网 · TypeScript——JavaScript的超集

实在不行就忽略类型检查:

// @ts-ignore
const app = new App({ i18n, store });

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值