facing-dev/vue-facing-decorator

Proposal: export the hooks methods as interfaces

sharadbrat opened this issue · 0 comments

Hello! I would like to propose some improvements to this library which in my opinion would enhance the DX. Consider the following code of component:

class MyComponent extends Vue {
  beforeDestroy(): void {
    // hook logic
  }
}

This component implements the beforeDestroy hook and runs some logic in this hook. Though there is a slight chance of an orthographic mistake when we are writing the code for such a component, like so:

class MyComponent extends Vue {
  beforDestroy(): void {
    // hook logic
  }
}

Now there is a mistake in the method beforDestroy and it is not going to be called as a Vue lifecycle method. This can be easily avoided by declaring the interface for each hook and implementing this interface within our component. Similarly to what Angular does. Example:

interface BeforeDestroy {
  beforeDestroy(): void;
}

class MyComponent extends Vue implements BeforeDestroy {
  // Compilation error: class MyComponent does not implement BeforeDestroy interface
  beforDestroy(): void {
    // hook logic
  }
}

This is a very easy change to be done, but can impact the DX significantly. Kindly consider this change.