Magento 2.2.2 – Error During Compilation

magento2magento2.2magento2.2.2

I had tried to compile the magento with this command sudo php bin/magento setup:di:compile when compiling process i had an error on one module as below

Errors during compilation:
Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\Grid\Collection
Incompatible argument type: Required type: \Magento\Framework\DB\Adapter\AdapterInterface. Actual type:
\Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\Grid\connection;
File:
/var/www/times/app/code/Smartwave/Dailydeals/Model/ResourceModel/Dailydeal/Grid/Collection.php

my collection.php file is below,

    <?php
    namespace Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\Grid;

    class Collection extends 
    \Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\Collection implements 
    \Magento\Framework\Api\Search\SearchResultInterface
    {
    /**
     * Aggregations
     *
     * @var \Magento\Framework\Search\AggregationInterface
     */
    protected $aggregations;

    /**
     * constructor
     *
     * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
     * @param \Psr\Log\LoggerInterface $logger
     * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
     * @param \Magento\Framework\Event\ManagerInterface $eventManager
     * @param $mainTable
     * @param $eventPrefix
     * @param $eventObject
     * @param $resourceModel
     * @param $model
     * @param $connection
     * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
     */
    public function __construct(
        \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
        \Magento\Framework\Event\ManagerInterface $eventManager,
        $mainTable,
        $eventPrefix,
        $eventObject,
        $resourceModel,
        $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document',
        $connection = null,
        \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
    ) {

        parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
        $this->_eventPrefix = $eventPrefix;
        $this->_eventObject = $eventObject;
        $this->_init($model, $resourceModel);
        $this->setMainTable($mainTable);
    }


    /**
     * @return \Magento\Framework\Search\AggregationInterface
     */
    public function getAggregations()
    {
        return $this->aggregations;
    }

    /**
     * @param \Magento\Framework\Search\AggregationInterface $aggregations
     * @return $this
     */
    public function setAggregations($aggregations)
    {
        $this->aggregations = $aggregations;
    }


    /**
     * Retrieve all ids for collection
     * Backward compatibility with EAV collection
     *
     * @param int $limit
     * @param int $offset
     * @return array
     */
    public function getAllIds($limit = null, $offset = null)
    {
        return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);
    }

    /**
     * Get search criteria.
     *
     * @return \Magento\Framework\Api\SearchCriteriaInterface|null
     */
    public function getSearchCriteria()
    {
        return null;
    }

    /**
     * Set search criteria.
     *
     * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
     * @return $this
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
    {
        return $this;
    }

    /**
     * Get total count.
     *
     * @return int
     */
    public function getTotalCount()
    {
        return $this->getSize();
    }

    /**
     * Set total count.
     *
     * @param int $totalCount
     * @return $this
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function setTotalCount($totalCount)
    {
        return $this;
    }

    /**
     * Set items list.
     *
     * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
     * @return $this
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function setItems(array $items = null)
    {
        return $this;
    }
}

And my Smartwave/Dailydeals/Model/ResourceModel/Dailydeal/collection file is below,

 <?php
 namespace Smartwave\Dailydeals\Model\ResourceModel\Dailydeal;

 class Collection extends 
 \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
 {
/**
 * ID Field Name
 *
 * @var string
 */
protected $_idFieldName = 'dailydeal_id';

/**
 * Event prefix
 *
 * @var string
 */
protected $_eventPrefix = 'sw_dailydeals_dailydeal_collection';

/**
 * Event object
 *
 * @var string
 */
protected $_eventObject = 'dailydeal_collection';

/**
 * Define resource model
 *
 * @return void
 */
protected function _construct()
{
    $this->_init('Smartwave\Dailydeals\Model\Dailydeal', 'Smartwave\Dailydeals\Model\ResourceModel\Dailydeal');
}

/**
 * Get SQL for get record count.
 * Extra GROUP BY strip added.
 *
 * @return \Magento\Framework\DB\Select
 */
public function getSelectCountSql()
{
    $countSelect = parent::getSelectCountSql();
    $countSelect->reset(\Zend_Db_Select::GROUP);
    return $countSelect;
}
/**
 * @param string $valueField
 * @param string $labelField
 * @param array $additional
 * @return array
 */
protected function _toOptionArray($valueField = 'dailydeal_id', $labelField = 'sw_product_sku', $additional = [])
{
    return parent::_toOptionArray($valueField, $labelField, $additional);
}
}

Best Answer

I had solved the error by replacing the $connection = null, with \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, within the constructor.

Thank guys for those who are tried to helping me. :)