HerringtonDarkholme / av-ts

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

More about vue-router lifecycle…… #78

Open whitetrefoil opened 6 years ago

whitetrefoil commented 6 years ago

Hi @HerringtonDarkholme,

This may need your help for a careful review and/or a local test (since it is a major change).

next() Function

According to the latest document, all next() function can be:

And for the beforeRouteEnter lifecycle, it has one more form:

next((vm) => {
    // ...
})

The type of vm here is this, the instance of current Component. But I failed to find a way to set it automatically. So I have to use a generic type (manually):

@Component()
class MyPage extends Vue {
    @Lifecycle
    beforeRouteEnter(to: Route, from: Route, next: NextFuncVm<MyPage>) {
        next((vm) => { // Now this "vm" is ": MyPage"
                // ...
        })
    }
}

vue-router & Other NPM Updates

As your previous comment, I tried to import the router related types from the official vue-router package. But if I use npm run compile then install it as dependency in my other local project, it caused a lot of type error (mostly about type of Vue).

Finally I did a clean update of NPM packages, now the errors have disappeared. But I didn't found the exact cause of this problem.

whitetrefoil commented 6 years ago

See the conflicts I just realized a big part of this PR has already been merged many days before (but I forget it). It just has not been published to NPM.

I'll take care of the conflict.

whitetrefoil commented 6 years ago

As conversation above about importing vue-router, this PR seems to have no use.

I can decline this PR. But I still suggest to release a version on the previous commit.

HerringtonDarkholme commented 6 years ago

I have bumped dep version locally. It seems webpack/ts-loader related deps have changed how declaration files emit. @whitetrefoil I guess updating deps breaks the build.

whitetrefoil commented 6 years ago
    "declarationDir": "dist",

in tsconfig.json should fix the build process.

HerringtonDarkholme commented 6 years ago

Great. I will update dependency.

@whitetrefoil can you pull the master branch and add Error to nextFunc? I think this pull request does improve the typing.