Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FunctionalComponent with array emits does not work as expected #2159

Closed
wonderful-panda opened this issue Sep 19, 2020 · 1 comment
Closed

Comments

@wonderful-panda
Copy link
Contributor

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 }) => {
  ...
}
@wonderful-panda
Copy link
Contributor Author

wonderful-panda commented Sep 19, 2020

(edit) I posted this comment here by mistake, this is comment for #2160.


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

Before:
image

After:
image

I'll fix it and push extra commits.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant