diff --git a/core/lib/Drupal/Core/Validation/ConstraintValidatorFactory.php b/core/lib/Drupal/Core/Validation/ConstraintValidatorFactory.php
index 1e3d62a5e6f4e61630c2edb0e99916538309f041..4e6bfe3091324634b78ef4c2a4df5c56e2aa7112 100644
--- a/core/lib/Drupal/Core/Validation/ConstraintValidatorFactory.php
+++ b/core/lib/Drupal/Core/Validation/ConstraintValidatorFactory.php
@@ -5,6 +5,7 @@
 use Drupal\Core\DependencyInjection\ClassResolverInterface;
 use Symfony\Component\Validator\Constraint;
 use Symfony\Component\Validator\ConstraintValidatorFactory as BaseConstraintValidatorFactory;
+use Symfony\Component\Validator\ConstraintValidatorInterface;
 
 /**
  * Defines a constraint validator factory that works with container injection.
@@ -26,7 +27,7 @@ public function __construct(ClassResolverInterface $class_resolver) {
   /**
    * {@inheritdoc}
    */
-  public function getInstance(Constraint $constraint) {
+  public function getInstance(Constraint $constraint): ConstraintValidatorInterface {
     $class_name = $constraint->validatedBy();
     // Constraint validator instances should always be initialized newly and
     // never shared, because the current validation context is getting injected