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

feat(sfc): support more ergnomic defineEmits type syntax #7992

Merged
merged 1 commit into from Mar 30, 2023
Merged

Conversation

yyx990803
Copy link
Member

Reference: https://vue-macros.sxzz.moe/macros/short-emits.html (note only the tuple syntax is adopted)

Provide a more ergonomic syntax for defineEmits() with types, by allow passing a type literal where the key is the event name and the value is the arguments type (must be an array type).

const emit = defineEmits<{
  foo: [id: string] // TS named tuple
  bar: any[]
  baz: []
}>()

emit('foo', 'hi')
// @ts-expect-error
emit('foo')

emit('bar')
emit('bar', 1, 2, 3)

emit('baz')
// @ts-expect-error
emit('baz', 1)

@yyx990803 yyx990803 merged commit 8876dcc into main Mar 30, 2023
5 checks passed
@yyx990803 yyx990803 deleted the short-emit branch March 30, 2023 11:24
@yyx990803
Copy link
Member Author

Codegen support added in ef73ea5

IAmSSH pushed a commit to IAmSSH/core that referenced this pull request May 14, 2023
IAmSSH pushed a commit to IAmSSH/core that referenced this pull request May 14, 2023
@wenfangdu
Copy link

@yyx990803 Why not support the function style declaration? It's closer to how we use defineProps<T>(), also, the args aren't just tuple labels and we can define the function return type that way.

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

Successfully merging this pull request may close these issues.

None yet

2 participants