Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular EventEmitter - is not a function ERROR #18578

Closed
mschneiderbauer opened this issue Jun 27, 2022 · 2 comments
Closed

Angular EventEmitter - is not a function ERROR #18578

mschneiderbauer opened this issue Jun 27, 2022 · 2 comments

Comments

@mschneiderbauer
Copy link

mschneiderbauer commented Jun 27, 2022

Hello!

Since upgrading to the latest Storybook version (6.5.9), I noticed multiple (console) errors in my stories which I suspect to cause other problems in my Storybook app as well. When a component calls emit() on an EventEmitter, it says that the emitter is not a function. This doesn't occur with every emitter though. Most of them still work and I don't see a pattern. The error listed below occurs in a lot of my stories now and I just can't figure out why. Is this a known issue?

Angular Version: 13.1.3
Storybook Version: 6.5.9

ERROR TypeError ctx.eventEmitter is not a function

ERROR TypeError: ctx.formDataChanged is not a function
    at StorybookWrapperComponent_Template_form_formDataChanged_0_listener (template.html:1:344)
    at executeListenerWithErrorHandling (core.mjs:14974:1)
    at Object.wrapListenerIn_markDirtyAndPreventDefault [as next] (core.mjs:15012:1)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:183:1)
    at SafeSubscriber.next (Subscriber.js:122:1)
    at Subscriber._next (Subscriber.js:72:1)
    at Subscriber.next (Subscriber.js:49:1)
    at EventEmitter_.next (Subject.js:39:1)
    at EventEmitter_.emit (core.mjs:22430:1)
    at FormComponent.<anonymous> (our-project.mjs:7382:1)

I also get the following warning:
Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot

I had to upgrade to the newer version because the previous version couldn't identify all of my components @Input()s.

@mschneiderbauer
Copy link
Author

Okay thanks, I get it now. Based on the comments I've read, the solution of removing the explicit type definition of the EventEmitters provided by @yngvebn worked for me.

This is the RegEx I used to replace all of my Emitters at once:
: EventEmitter<(.*)> = new EventEmitter<(.*)>\(\);
= new EventEmitter<$1>();

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

No branches or pull requests

2 participants