How do I add a Twig Filter? I made a custom module that extends TwigExtension, where I define all sort of custom twig filters. It worked well until the update to 8.3, where TwigExtension changed slightly:

/**
* Constructs \Drupal\Core\Template\TwigExtension.
*
* @param \Drupal\Core\Render\RendererInterface $renderer
*   The renderer.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
*   The URL generator.
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
*   The theme manager.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
*   The date formatter.
*/
public function __construct(RendererInterface $renderer, 
  UrlGeneratorInterface $url_generator, ThemeManagerInterface 
  $theme_manager, DateFormatterInterface $date_formatter) {
  $this-&gt;renderer = $renderer;
  $this-&gt;urlGenerator = $url_generator;
  $this-&gt;themeManager = $theme_manager;
  $this-&gt;dateFormatter = $date_formatter;
}


My service yaml looked like this:

services:
  custom_twig.twig.extension:
    arguments: ['@renderer']
class: Drupal\custom_twig\TwigExtension\LabTwigExtension
tags:
  - { name: twig.extension }


And I changed the services to have the new required ones.

services:
  custom_twig.twig.extension:
    arguments: ['@renderer', '@url_generator', '@theme.manager','@date.formatter']
class: Drupal\custom_twig\TwigExtension\LabTwigExtension
tags:
  - { name: twig.extension }


Although I set the correct arguments, Drupal throws an error:


  Recoverable fatal error: Argument 2 passed to Drupal\Core\Template\TwigExtension::__construct() 
      must implement interface Drupal\Core\Routing\UrlGeneratorInterface, none given, called in /A


I am fairly certain that url_generator implement UrlGeneratorInterface. Is there anything else I got wrong?
If you are using Twig Extender , try updating it to version 8.x-2.0-rc1. It worked for me