Skip to content

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

Closed
@krissrex

Description

@krissrex

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions