Skip to content

feat: add lifecycle types into vue instance type #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 11, 2020
Merged

Conversation

ktsn
Copy link
Member

@ktsn ktsn commented Nov 11, 2019

fix #338
fix #297

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

P4sca1 commented Jan 11, 2020

@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 GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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