Conversation

ktsn

fix #338
fix #297

@ktsnktsn changed the title fix: add lifecycle types into vue instance type feat: add lifecycle types into vue instance type Jan 11, 2020
@ktsnktsn merged commit 506247b into master Jan 11, 2020
@ktsnktsn deleted the add-lifecycle-types branch January 11, 2020 03:45
@P4sca1

@ktsn In the README, vm: V should be replaced by vm: Vue.

Comment on lines +204 to +233
If you want to make it work with custom hooks, you can manually add it by yourself:

```ts
import Vue from 'vue'
import { Route, RawLocation } from 'vue-router'

declare module 'vue/types/vue' {
// Augment component instance type
interface Vue {
beforeRouteEnter?(
to: Route,
from: Route,
next: (to?: RawLocation | false | ((vm: V) => any) | void) => void
): void

beforeRouteLeave?(
to: Route,
from: Route,
next: (to?: RawLocation | false | ((vm: V) => any) | void) => void
): void

beforeRouteUpdate?(
to: Route,
from: Route,
next: (to?: RawLocation | false | ((vm: V) => any) | void) => void
): void
}
}
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ktsn In which file should this code be added?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a new .ts file in your project and write in it. You may want to see Vue.js TypeScript guide. https://vuejs.org/v2/guide/typescript.html#Augmenting-Types-for-Use-with-Plugins

Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

[discussion] Add LifecycleHook interface definition How are types added to registered hook?