question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript definitions not working?

See original GitHub issue

Hey guys!

I’m currently trying to upgrade our project running vue 2.3x to vue 2.5.13 and i can’t make it use VueRessource.

My vue imports and use are declared this way

import Vue from 'vue';
import VueRouter from 'vue-router';
import VueResource from 'vue-resource';
import Vue2Filters from 'vue2-filters';
import { Validator } from 'vee-validate';
import BootstrapVue from "bootstrap-vue";
import VueI18n from 'vue-i18n';


Vue.use(Vue2Filters);
Vue.use(VueResource);
Vue.use(VueRouter);
Vue.use(VueI18n);
Vue.use(infiniteScroll);
Vue.use(BootstrapVue);

But the TS compilation fails with the following error :

(61,9): error TS2345: Argument of type 'typeof "/home/clement/workspace/pingflow/v3/fry/node_modules/vue-resource/types/index"' is not assignable to parameter of type 'PluginObject<any> | PluginFunction<any>'.
  Type 'typeof "/home/clement/workspace/pingflow/v3/fry/node_modules/vue-resource/types/index"' is not assignable to type 'PluginFunction<any>'.
    Type 'typeof "/home/clement/workspace/pingflow/v3/fry/node_modules/vue-resource/types/index"' provides no match for the signature '(Vue: VueConstructor<Vue>, options?: any): void'.

I’m running the latest libraries versions : vue@2.5.13 and vue-resource@1.3.6 (double checked in the node_modules) If it’s of any help, i’m using yarn.

Cheers,

Clément

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
csr632commented, Jun 11, 2018

As a temporary workaround, I manually add some declaration to projectRoot/node_modules/vue-resource/types/vue.d.ts:

/**
 * Extends interfaces in Vue.js
 */

import Vue from "vue";
import { HttpHeaders, HttpOptions, HttpResponse, $http, $resource } from "./vue_resource";

declare module "vue/types/options" {
    interface ComponentOptions<V extends Vue> {
        http?: (HttpOptions & { headers?: HttpHeaders } & { [key: string]: any })
    }
}

declare module "vue/types/vue" {
    interface Vue {
        $http: {
            (options: HttpOptions): PromiseLike<HttpResponse>;
            get: $http;
            post: $http;
            put: $http;
            patch: $http;
            delete: $http;
            jsonp: $http;
        };
        $resource: $resource;
    }

    interface VueConstructor {
        http: {
            (options: HttpOptions): PromiseLike<HttpResponse>;
            get: $http;
            post: $http;
            put: $http;
            patch: $http;
            delete: $http;
            jsonp: $http;
        };
        resource: $resource;
    }
}
4reactions
csr632commented, Jun 11, 2018

Using 1.5.1, still can’t access $http or http in Vue. screenshot

I have import and use vue-resource in main.ts:

according to vue docs , someone have to do something like:

declare module 'vue/types/vue' {
  // Global properties can be declared
  // on the `VueConstructor` interface
  interface VueConstructor {
    $myGlobal: string
  }
}

But vue-resource is not doing something like this, which make $http not accessable from global Vue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript type definitions not working with JavaScript in ...
I'm working on a project with mixed TypeScript and JavaScript. We use ThreeJS, and we use type definitions for it.
Read more >
custom typescript definitions not working on windows 10
Here I want to use a package called vueisotope that has no type definition file. To make it work with typescript I changed...
Read more >
Go to definition not working with TypeScript
Either after about 10-20 minutes intellisense started working for the typescript project or it never works. There were no errors at all.
Read more >
TypeScript: JavaScript With Syntax For Types.
TypeScript is JavaScript with syntax for types. TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at ......
Read more >
Importing TypeScript Definitions - C#/XAML for HTML5 - cshtml5
When a TypeScript Definition file is open in a tab in Visual Studio, many misleading errors may be displayed, and some TypeScript code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found