Skip to content

Types: defineEmits does not narrow type on typing #13935

@ludwig801

Description

@ludwig801

Vue - Official extension or vue-tsc version

3.0.8

VSCode version

1.104.2

Vue version

3.5.13

TypeScript version

5.8.3

Steps to reproduce

Given the following emit definition:

const givenEmit = defineEmits<{
  open: [payload: number];
  close: [payload: string];
}>();

What is expected?

When I type givenEmit("open", ... ) I expect the following suggestion to be of type number, but both number and string options are provided, as if no narrowing could be possible:

I expected the type of givenEmit to be something like:

type ExpectedType = <
  TEvent extends "open" | "close",
  TEventArgs extends { open: [payload: number]; close: [payload: string] },
>(
  event: TEvent,
  ...args: TEventArgs[TEvent]
) => void;

So that when I typed givenEmit("open", ... ) it would be able to narrow down the selected option, but this seems not to happen.

What is actually happening?

The type is being set as an intersection of all possible types, and therefore narrowing is not happening:

Image

Link to minimal reproduction

No response

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    🍰 p2-nice-to-havePriority 2: this is not breaking anything but nice to have it addressed.scope: types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions