mvertopoulos / vue-msal

Vue plugin for using Microsoft Authentication Library (MSAL)
MIT License
123 stars 66 forks source link

Typescript support #18

Closed drovani closed 4 years ago

drovani commented 4 years ago

I'm not sure if it's better to comment on #4, or create a new one - but I, too, am having trouble getting this to work with Typescript.

My main.ts file looks like this:

import Vue from "vue";
import msal from "vue-msal";

Vue.use(msal, {
  auth: {
    clientId: "clientid"
  {
});

new Vue({
    //...
    created() {
        if (!this.$msal.isAuthenticated()) {
            this.$msal.signIn();
        }
    }
});

I get the error message of Could not find a declaration file for module 'vue-msal'. Type 'npm install @types/vue-msal' if it exists or add a new declaration (.d.ts) file containing 'declare module 'vue-msal';'. I have created the file /src/vue-msal.shims.d.ts:

declare module 'vue-msal'; Doing so resolves the first error. However, now I am receiving an error on the this.$msal line of Property '$msal' does not exist on type 'CombinedVueInstance<Vue, Data, Methods, Computed, Readonly<Record<PropNames, any>>>'. Based on a bit of Googling, the solution seems to be "Augmenting Types for Use with Plugins"

I created another shim file /src/vue.msal.shims.d.ts with the content:

import Vue from 'vue';
import msal from 'vue-msal';

declare module 'vue/type/vue'{
  interface Vue{
    $msal: msal;
  }
}

Now I have an issue where the $msal: msal; line in the shims file has an error of Cannot use namespace 'msal' as a type.. At this point I'm lost as to what I need to put in this shim to make everything work. Do you have an pointers that might help?

Thank you.

blakeja commented 4 years ago

Was anyone able to resolve this?

blakeja commented 4 years ago

Had to do the following to get this working:

import Vue from 'vue';
import { MSALBasic } from 'vue-msal/lib/src/types'

declare module 'vue/types/vue' {
  interface Vue {
    $msal: MSALBasic;
  }
}

@drovani was close, but there was typo: declare module 'vue/type/vue' should have been declare module 'vue/types/vue'.

I believe these problems could be avoided by including a type definition file in the plugin itself, see Augmenting Types for Use with Plugins as mentioned above.

drovani commented 4 years ago

Coming back to this, I never did get it fully resolved, but I have moved away from this package. As such, I am closing out this issue.

terle commented 3 years ago

@drovani just out of curiosity, which package did you move towards then?

drovani commented 3 years ago

I started hand-rolling a solution, but then the entire project got scrapped, so I wasn't able to spend the time to get it working.

thomas-jackson-finx commented 2 years ago

Hello, Can anyone help me with this problem?

image