Skip to content

Vue 3 + Typescript: "setup" function breaks emits typing #5343

Closed
@iliubinskii

Description

@iliubinskii

Version

3.0.0

Reproduction link

github.com

Steps to reproduce

  1. Clone reproduction repository
  2. Run "validate" script: npm run validate
    OR
    open Sample1.ts and Sample2.ts in Visual Studio Code.

What is expected?

I expect to see two errors:

One from

emit("wrong-event-name");

in Sample1.ts

And another one from

this.$emit("wrong-event-name");

in Sample2.ts

What is actually happening?

I see only one error - from Sample2.ts


In Sample2 defineComponent correctly determines emits type as:

{
    event(): boolean;
}

image

In Sample1 it uses EmitsOptions type because of _props and { emit } args.

image

If you remove args, emits type is determined correctly, but in this case you will not have access to emit function which is not suitable.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions