DEV Community

Discussion on: vue-typed-emit

Collapse
 
romalyt profile image
Roman • Edited

Hey! Thanks for the article, nice solution.

What do you think about new emits property? It allows you to type hint emits when using with TS. For example:

export default defineComponent({
  emits: {
    'foo': (arg: string) => { // some validation logic for runtime },
  },
  mounted () {
    tis.$emit('foo', 1) // type error, you can emit only strings for 'foo' event
  },
})
Enter fullscreen mode Exit fullscreen mode

Further reading:
v3.vuejs.org/api/options-data.html...
github.com/vuejs/rfcs/blob/master/...