Skip to content

FunctionalComponent with array emits does not work as expected #2159

@wonderful-panda

Description

@wonderful-panda

Version

3.0.0

Reproduction link

wonderful-panda@5cb6c2d

Steps to reproduce

Pull linked commit, and run yarn test-dts

This is a problematic code

const Qux: FunctionalComponent<{}, ['foo', 'bar']> = (props, { emit }) => {
  emit('foo')  // OK
  emit('foo', 1, 2)  // OK
  emit('bar')  // TS2345: Argument of type '"bar"' is not assignable to parameter of type '"foo"'
}

What is expected?

No compile error.

What is actually happening?

TS2345 error is reported


Below code works as expected, but I think ['foo', 'bar'] is more straightforward and preferable.

const Qux: FunctionalComponent<{}, ('foo' | 'bar')[]> = (props, { emit }) => {
  ...
}

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