se-panfilov / vue-notifications

Vue.js agnostic library for non-blocking notifications
https://se-panfilov.github.io/vue-notifications/
MIT License
698 stars 54 forks source link

TS with decorators #198

Open alvaro-canepa opened 4 years ago

alvaro-canepa commented 4 years ago

Using TS with decorators is not possible to set the notificacions object, as say the doc. This must be a function type, returning the object options. But TS give error Property $error does not exists.

I made a mixin to use it.

// main.ts
import Component from "vue-class-component";
Component.registerHooks(["notifications"]);

// mixins/notify.ts
import { Component, Vue } from "vue-property-decorator";

@Component
export default class Notify extends Vue {
  notifications() {
    return {
      $error: {
        type: "error",
        title: "",
        message: ""
      },
      $warning: {
        type: "warning",
        title: "",
        message: ""
      },
      $info: {
        type: "info",
        title: "",
        message: ""
      },
      $success: {
        type: "success",
        title: "",
        message: ""
      }
    };
  }
}

I think the fixed was in line 80 https://github.com/se-panfilov/vue-notifications/blob/ffdd19cacff28a1692eb9ac4886ff5b5c434c9c2/src/vue-notifications.ts#L80

pluginOptions[methodName] must be checked if is a function. something like

const pluginOptionsData = typeof pluginOptions === 'function' ? pluginOptions.call() : pluginOptions;
const methodConfig = pluginOptionsData ? pluginOptionsData[methodName] : {};