Skip to content
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

Expose typings for Plugins #269

Closed
posva opened this issue Dec 11, 2020 · 6 comments · Fixed by #282
Closed

Expose typings for Plugins #269

posva opened this issue Dec 11, 2020 · 6 comments · Fixed by #282
Labels
enhancement New feature or request typescript

Comments

@posva
Copy link
Member

posva commented Dec 11, 2020

I think it would be helpful to expose the Instance type so plugins can type the argument (https://vue-test-utils.vuejs.org/v2/guide/plugins.html#writing-a-plugin) as well as adapting the install function to infer the options parameter:

    install(handler: (instance: Instance) => Record<string, any>, options?: Record<string, any>): void;

Similar to vuejs/core#2758

@posva posva added the enhancement New feature or request label Dec 11, 2020
@lmiller1990
Copy link
Member

lmiller1990 commented Dec 14, 2020

Oh cool, this is a good idea. I will give this one at try. If you want to make a PR before I do, go for it 👍

@lmiller1990
Copy link
Member

lmiller1990 commented Dec 15, 2020

Just to confirm @posva, are you referring to

  • the plugin system that only exists in VTU for extending wrapper (which you linked to)?
  • as opposed to plugins as in app.use (like #2758)?

We should probably support both with correct types where possible.

@lmiller1990
Copy link
Member

Edit: Seems VTU plugins was not actually working properly in the first place, fixed: #276

Are you using this for the mock router? Sorry I did not have time to work on that lately... :(

@posva
Copy link
Member Author

posva commented Dec 15, 2020

the plugin system that only exists in VTU for extending wrapper (which you linked to)?

Yes!
Specifically, one should be able to do something like this:

function myPlugin(wrapper: Instance, options: { n: number }) {}

// @ts-error
config.plugins.VueWrapper.install(myPlugin, {n: true})

That's why I was referring to https://github.com/vuejs/vue-next/pull/2758/files

I haven't had much time for the router mock, no worries. I was trying to release an initial version soon to get some feedback from the community and add features

@lmiller1990
Copy link
Member

Cool, I can update the typings on top of #276.

No problem, I will try test the mock router soon (or have a hack on it if it's not ready yet).

@posva
Copy link
Member Author

posva commented Dec 22, 2020

Sorry for the delay! I submitted a PR
I'm finishing up an initial 0.0.1 version for the mock but at the end I don't think I need even need the plugin API. But It could be useful in the future to add functions to the wrapper or even the router!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants