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

Wrong Typescript signature for Wrapper.emitted(str) #924

Closed
krissrex opened this issue Aug 15, 2018 · 3 comments · Fixed by #933
Closed

Wrong Typescript signature for Wrapper.emitted(str) #924

krissrex opened this issue Aug 15, 2018 · 3 comments · Fixed by #933
Labels

Comments

@krissrex
Copy link

https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/types/index.d.ts#L107

Version

1.0.0-beta.24

Steps to reproduce

const wrapper = shallowMount(MyVueComponent);
wrapper.trigger('click'); // any event

const myEvent: string = wrapper.emitted('click')[0][0]; // Issue here!!

What is expected?

wrapper.emitted('click')[0][0]; should have signature any.

What is actually happening?

It has signature any[].


The fix would be 2 method signatures:

emitted (): { [name: string]: Array<Array<any>> }
emitted (event: string): { [name: string]: Array<any> }

https://jsfiddle.net/1b68eLdr/55727/

This would make typescript happy.

Note: If you were to actually implement this signature using typescript, you can't (because of 2 methods with the same name, but different signatures). You could cast the right hand side to any though, and it will work.

@krissrex
Copy link
Author

As a workaround until this is fixed, put this in a vue-test-utils.d.ts:

import { Wrapper } from '@vue/test-utils'
import Vue from 'vue';

declare module '@vue/test-utils' {
  interface Wrapper<V extends Vue> {
    emitted(): { [name: string]: Array<Array<any>> };
    emitted(event: string): Array<Array<any>>;
  }
}

@eddyerburgh
Copy link
Member

Thanks for the bug report.

Would you like to make a PR implementing the fix?

@krissrex
Copy link
Author

@eddyerburgh I made a mistake in my actual paragraph: the signature should still be a nested array.

f51c7cc#diff-b801fc35a5096ae10463a20e928fb818R108

The Jsfiddle and workaround comment have it correctly:

emitted(): { [name: string]: Array<Array<any>> };
emitted(event: string): Array<Array<any>>;

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.

2 participants