You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Obviously you don't have to call it emitter, but whatever you do call it has to be consistent with the type declaration below.
I think if you're not running TS in strict mode, or you don't need the this.emitter in your other methods to typecheck, you're done, but if you are in strict mode, you need some additional bits.
For the new property to typecheck when using it, you have to do some module augmentation stuff. Vue.js docs. I created this:
// in src/typings/mitt.d.tsimport{Emitter}from"mitt";declare module '@vue/runtime-core'{exportinterfaceComponentCustomProperties{emitter: Emitter<any>}}
Lastly...I was using this shorthand for defining components:
exportdefault{
....
And this seems to not work with the module augmentation. Instead I had to do this, as the docs suggest:
Finally, if you're using VS Code, you might get a little error (Property 'emitter' does not exist on type...) where you're referencing emitter in your main application. I found that restarting VS Code fixed it (?!) so...you might give that a try.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey, I'm working on getting Mitt working with the tech in the title and thought I'd share what I found to work.
First, for attaching mitt to Vue at all, I combined the mitt docs and the Vue.js 3 migration docs to get this:
Obviously you don't have to call it
emitter
, but whatever you do call it has to be consistent with the type declaration below.I think if you're not running TS in strict mode, or you don't need the
this.emitter
in your other methods to typecheck, you're done, but if you are in strict mode, you need some additional bits.For the new property to typecheck when using it, you have to do some module augmentation stuff. Vue.js docs. I created this:
Lastly...I was using this shorthand for defining components:
And this seems to not work with the module augmentation. Instead I had to do this, as the docs suggest:
Finally, if you're using VS Code, you might get a little error (
Property 'emitter' does not exist on type...
) where you're referencingemitter
in your main application. I found that restarting VS Code fixed it (?!) so...you might give that a try.Beta Was this translation helpful? Give feedback.
All reactions