Skip to content

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

Merged
yyx990803 merged 1 commit into
mainfrom
short-emit
Mar 30, 2023
Merged

yyx990803 merged 1 commit into
mainfrom
short-emit

Conversation

@yyx990803

Copy link
Copy Markdown
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
@yyx990803
yyx990803 deleted the short-emit branch March 30, 2023 11:24
@yyx990803

Copy link
Copy Markdown
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
Copy Markdown

@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.

2 participants