Subscribe on changes!

FunctionalComponent with array emits does not work as expected

avatar
Sep 19th 2020

Version

3.0.0

Reproduction link

https://github.com/wonderful-panda/vue-next/commit/5cb6c2d9b3524538235730d22ac2485b5b697b83

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 }) => {
  ...
}
avatar
Sep 19th 2020

(edit) I posted this comment here by mistake, this is comment for https://github.com/vuejs/vue-next/pull/2160.


Sorry, this fix has a problem. (type of $emit is broken)

Before: image

After: image

I'll fix it and push extra commits.