nextcloud_composer
nextcloud_composer copied to clipboard
Incompatible types found for T
I get an error from psalm regarding the event listener.
$context->registerEventListener(AddFeaturePolicyEvent::class, AddFeaturePolicyListener::class);
will produce
ERROR: InvalidArgument - lib/AppInfo/Application.php:60:13 - Incompatible types found for T (OCP\Security\FeaturePolicy\AddFeaturePolicyEvent is not in OCP\EventDispatcher\Event) (see https://psalm.dev/004)
$context->registerEventListener(AddFeaturePolicyEvent::class, AddFeaturePolicyListener::class);
My listener looks like this:
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Security\FeaturePolicy\AddFeaturePolicyEvent;
class AddFeaturePolicyListener implements IEventListener
{
public function handle(Event $event): void
{
if (!($event instanceof AddFeaturePolicyEvent)) {
return;
}
//...
}
}
Changing the $event type to AddFeaturePolicyEvent does not work. Do you have an idea how this can be resolved?
Yeah, this is unfortunately known. We had a discussion and a few attempts of fixes at https://github.com/nextcloud/server/pull/28338. I think unless Psalm got wiser in the meantime we should possibly drop the generics from the listener. After all it's possibly to use one listener to react to more than one dynamic type.
See https://github.com/vimeo/psalm/issues/7549