sebinside / StreamAwesome

Stream Awesome - The Stream Deck Icon Generator using Font Awesome
MIT License
52 stars 15 forks source link

refactor: implement emit types #199

Closed MichaHuhn closed 5 months ago

MichaHuhn commented 5 months ago

Currently, emits are listed by using the runtime declaration without types:

defineEmits(['updateStyle', 'updateFamily', 'updateSize'])

This PR implements emit types by using the type-based declaration:

const emit = defineEmits<{
  updateSize: [size: number]
  updateFamily: [family: FontAwesomeFamily]
  updateStyle: [style: FontAwesomeStyle]
}>()

The type-based declaration provides type-safety and autocompletion when using emits which is super awesome.

Currently, it's possible to emit any value. With this PR, only the specified values are allowed and such errors will be caught:

image


Here is an example from the documentation:

image

https://vuejs.org/api/sfc-script-setup.html#type-only-props-emit-declarations