Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes
emits
in the Vue components to use the object syntax, which allows specifying the type(s) of the thing(s) you are emitting. This accomplishes two things. The less interesting one is that the types are checked within the components itself, so you don't accidentally emit the wrong type. The other and more significant is that if you use a tool which typechecks Vue templates such as vue-tsc, it will check that the callback you use as an event listener in the parent conforms to what's being emitted. E.g. if you do@update:modelValue=functionThatTakesAString
on aSwitch
, you'll get a type error because we've declared thatSwitch
emits a boolean.I went a bit back and forth on whether I should use
any
orunknown
forListBox
andRadio Group
. I landed onany
because I thinkunknown
is likely to be unergonomic. In almost all cases you'll probably use these components in a way where the same type is always being emitted and withunknown
you'll have to always cast it to that type. You can't cast inside Vue templates because Typescript syntax isn't allowed, so you're forced to create a function in the script section just to do the cast.any
is a bit less safe but it avoids these issues. It's still an improvement on the current situation because we declare that only one value is emitted, so a callback with multiple arguments would be flagged.The reason all of them are arrow functions that just return true is that this syntax allows for runtime validation of emits. Returning true just says that the emit is valid.