How to resolve the "Type "mixed" cannot be nullable" error that appears during installation when Live Search is used?

How to resolve the "Type "mixed" cannot be nullable" error that appears during installation when Live Search is used?

When running the php bin/magento setup:di:compile command on Magento versions that are older than 2.4.6, the following error message might appear:
Type "mixed" cannot be nullable: Class Magento\LiveSearchAdapter\Model\QueryArgumentProcessor\FilterHandler\FilterHandlerFactory\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only.        

It is caused by a core Magento bug related to the absence of support for mixed type. As mixed type was added to v.3.0.1 of the magento/module-live-search-adapter module, its presence interferes into code compilation. There are two alternative solutions for this issue:
  1. To update Magento version to 2.4.6 or newer;
  2. Or, to apply a patch file with the fix that was prepared by Magento Community.