2

I am working with Typescript on a Vue project which uses vue-resource. The project is working fine, but I am getting a typescript compiler error.

enter image description here enter image description here

Notice that I am able to use the module using this.$http in my components.

I have checked this, this, and this, answers but none of these helped. Is there a work around for this? Or is there a way to set global options in Vue-Resource with Typescript? Or a way to ignore the error altogether?

[Edit] Workaround (also attached as my answer):

One of the workarounds from @Styx 's comment (Github solution is significantly hacky as I refrain from manually making modifications to vue-resource/types/vue.d.ts), mentioning here anyway.

Use generics and typecast Vue to any, example <any>Vue.http. This however, might result in tslint warning, hence I solved this by using (Vue as any) and then access (Vue as any).http

metamemelord
  • 500
  • 1
  • 7
  • 19

2 Answers2

4

I think you need to add a new definition file named 'http.d.ts' where your main.ts is located and the following:

import Vue from 'vue';

declare module 'vue/types/vue' {
  interface VueConstructor {
    http: any;
  }
}

This should solve the error.

Wahib Kerkeni
  • 566
  • 7
  • 10
1

From the comments, I got this link. You can read through, here's a workaround:

Use generics and typecast Vue to any, example <any>Vue.http. This however, might result in tslint warning, hence I solved this by using (Vue as any) and then access (Vue as any).http

metamemelord
  • 500
  • 1
  • 7
  • 19