#How to use an optional output?

22 messages ยท Page 1 of 1 (latest)

lost peak
#

If a component has an optional output, in my case it looks like this: change?: EventEmitter<object>;, if I try to use it like this: (change)="handleChange($event), I get this error: Object is possibly 'undefined'.
How can I attach the handleChange function to the event only if it actually exists?

#

How to use an optional output?

clear gust
#

Why do you have an optional @Output?

lost peak
topaz estuary
#

Might wanna report it as a bug to the maintainer

true scroll
#

Optional outputs, that's new ๐Ÿ˜„

#

How can they even be optional?

#

WHat library is this? I'd be curious to look at the code.

true scroll
#

That's weird yeah.

topaz estuary
#

Probably just went with the ? by default from all the inputs above heheh

#

But that shows they never even tested it ๐Ÿ˜„

#

(cause it's 5 years old)

#

But given it's all any's and object's anyway...

clear gust
topaz estuary
#

Nah there is a fix

#

Just nobody merges it

#

Somebody should probably tell that guy it doesn't make the handler required

#

I guess they don't really know Angular and just provided a wrapper the best way they could

clear gust
#

I knew the PR, but it's been a while and nobody merged...
And I've seen really funny "workarounds" suggested, like (change?) ๐Ÿ˜„

topaz estuary
#

Yeah which probably just waits for an event called 'change?' heheh