Change record status: 
Project: 
Introduced in branch: 
10.2.x
Introduced in version: 
10.2.0
Description: 

A new mechanism was added to deprecate variables in twig templates. Now the key deprecations is supported inside the variables array and will trigger a deprecation error for each deprecated variable.

Before

function my_custom_module_theme($existing, $type, $theme, $path) {
  $items['custom_template'] = [
    'variables' => [
      'result' => NULL,
    ],
  ];
  return $items;
}

After

function my_custom_module_theme($existing, $type, $theme, $path) {
  $items['custom_template'] = [
    'variables' => [
      'result' => NULL,
      'new_result' => NULL,
      'deprecations' => [
        'result' => "'result' is deprecated in drupal:X.0.0 and is removed from drupal:Y.0.0. Use 'new_result' instead. See https://www.example.com."
      ]
    ],
  ];
  return $items;
}

The deprecations key expects an array with all the variables to be deprecated. The key of the deprecations array expects the variable name and the value will be the message to be triggered.

Impacts: 
Module developers
Themers