Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript declaration is missing #8

Open
blugri opened this issue Feb 22, 2020 · 5 comments
Open

Typescript declaration is missing #8

blugri opened this issue Feb 22, 2020 · 5 comments

Comments

@blugri
Copy link

blugri commented Feb 22, 2020

npm install @types/vue-application-insights
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fvue-application-insights - Not found
npm ERR! 404
npm ERR! 404 '@types/vue-application-insights@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

@DavidDeSloovere
Copy link

DavidDeSloovere commented Mar 5, 2020

Would be great if the package included typescript declaration. Separate types under @types is only an option if we can't get it in the original package.
An example from another vue plugin: https://github.com/MatteoGabriele/vue-gtag (I'm using this because I jsut add this before vue-application-insights)

Something to get started:

declare module "vue-application-insights" {
  import VueRouter from "vue-router";
  import _Vue from "vue";

  export interface VueApplicationInsights {
    trackEvent(name: string, options: any): void;
  }
  export interface PluginOptions {
    id: string;
    baseName?: string;
    router?: VueRouter;
  }
  export class VueApplicationInsightsPlugin {
    static install(Vue: typeof _Vue, options: PluginOptions): void;
  }

  export default VueApplicationInsightsPlugin;

  module "vue/types/vue" {
    interface Vue {
      $appInsights: VueApplicationInsights;
    }
  }
}

@ux-engineer
Copy link

This would be nice to have.

@StefanSchoof
Copy link
Contributor

@DavidDeSloovere thanks, I used this and extended it to use types form @microsoft/applicationinsights-web

declare module "vue-application-insights" {
    import { ApplicationInsights, IConfiguration } from "@microsoft/applicationinsights-web";
    import { IConfig } from "@microsoft/applicationinsights-common";
    import VueRouter from "vue-router";
    import _Vue from "vue";

    export interface VueApplicationInsightsPluginOptions {
        id?: string;
        appInsightsConfig?: IConfiguration & IConfig
        baseName?: string;
        router?: VueRouter;
    }
    export class VueApplicationInsightsPlugin {
        static install(Vue: typeof _Vue, options: VueApplicationInsightsPluginOptions): void;
    }

    export default VueApplicationInsightsPlugin;

    module "vue/types/vue" {
        interface Vue {
            $appInsights: ApplicationInsights;
        }
    }
}

@ux-engineer
Copy link

@StefanSchoof thanks! But how do you use SeverityLevels enum statically (after build)?

@StefanSchoof
Copy link
Contributor

@ux-engineer
I imported this enum from @microsoft/applicationinsights-web

import { SeverityLevel } from "@microsoft/applicationinsights-web";
...
Vue.config.warnHandler = (msg, vm, trace) => {
  vm.$appInsights.trackTrace({
    message: msg,
    properties: { trace },
    severityLevel: SeverityLevel.Warning
  });
  // Same as https://github.com/vuejs/vue/blob/b51430f598b354ed60851bb62885539bd25de3d8/src/core/util/debug.js#L24
  console.error(`[Vue warn]: ${msg}${trace}`);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants