Skip to content

How are types added to registered hook? #297

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

Closed
yankeeinlondon opened this issue Dec 13, 2018 · 2 comments · Fixed by #371
Closed

How are types added to registered hook? #297

yankeeinlondon opened this issue Dec 13, 2018 · 2 comments · Fixed by #371
Labels

Comments

@yankeeinlondon
Copy link
Contributor

I am trying to use NUXT with Typescript and really want the class based syntax this module provides but when I looked into the nuxt-class-components modules I saw they were mainly just adding lifecycle hooks via your registerHooks but then I'm not getting any type information from those hooks which is a shame.

I think it would be nice to state in the documentation how one can achieve this.

@ktsn
Copy link
Member

ktsn commented Jan 24, 2019

You can extend Vue instance method by using module augmentation technique. https://vuejs.org/v2/guide/typescript.html#Augmenting-Types-for-Use-with-Plugins

But I'm not sure we should state it in docs since the methods are not actually in the Vue instance.

@ktsn ktsn added the docs label Jan 24, 2019
@marco-quintella
Copy link

marco-quintella commented May 13, 2019

@ksnyde You need to augment the type definition for your new lifecycle hooks. Since the TS don't have any previous info about what your building. You need to provide it. This can be done with .d.ts file augmenting the hooks definitions in the module 'vue/types/options' with your own definitions. Try to make a test including a simple string in the definition from your hook and check if you will get the type information from it.

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

Successfully merging a pull request may close this issue.

3 participants