HerringtonDarkholme / av-ts

A modern, type-safe, idiomatic Vue binding library
MIT License
216 stars 11 forks source link

[#74] Fix wrong typing caused in #72 #75

Closed whitetrefoil closed 6 years ago

whitetrefoil commented 6 years ago

I merged some next functions, but I still cannot find proper way to fix:

  1. Still have to manually specify NextFunc or NextFuncVm for beforeRouteEnter.
  2. Still have to manually specify the generic MyComponent for NextFuncVm<MyComponent>.
  3. Cannot set this in beforeRouteEnter to void:

    export default class MyPage extends Vue {
    @Prop id = p(String)
    
    @Lifecycle
    async beforeRouteEnter(to: Route, from: Route, next: NextFuncVm<MyPage>) {
    console.log(this.id) // No `id` on `this` here.
    next((vm) => {
      // `id` can only be referred on `vm`.
      console.log(vm.id)
    })
    }
HerringtonDarkholme commented 6 years ago

As far as I can tell, these 3 items aren't fixable in TypeScript design. I think we should let them be there.

whitetrefoil commented 6 years ago

Hoping new features will come in future versions of TS. (although it has already been very complex)

whitetrefoil commented 6 years ago

Just found there may have other legal arguments for the next functions, will take a look at them. Hold this PR...

whitetrefoil commented 6 years ago

Should I install vue-router as dependency then use NavigationGuard from it directly?

whitetrefoil commented 6 years ago

I copied some definition code from vue-router, now the next function can accept different types(callback, false, Location) of arguments at same time. (like in README)

HerringtonDarkholme commented 6 years ago

I personally prefer code duplication over importing a whole library. Is this pull request good to go?

whitetrefoil commented 6 years ago

Me too. I've tried installing vue-router first, and compiled successfully.

But I had problem when install the compiled code as dependency in other projects - tsc said cannot found stuff av-ts imported from external libs (vue & vue-router). As a result I cannot test my changes.

So for safety purpose, I copied the code from vue-router instead of import types from it.