diff --git a/core/lib/Drupal/Core/TypedData/DataReferenceBase.php b/core/lib/Drupal/Core/TypedData/DataReferenceBase.php
index a41b01c65df6fb95ca7f7d180c07cafcaf41035a..2e0cbc524a33d1b96ddced935f445a6bb3022d81 100644
--- a/core/lib/Drupal/Core/TypedData/DataReferenceBase.php
+++ b/core/lib/Drupal/Core/TypedData/DataReferenceBase.php
@@ -54,6 +54,9 @@ public function setValue($value, $notify = TRUE) {
    * {@inheritdoc}
    */
   public function getString() {
+    if (!method_exists($this, 'getType')) {
+      throw new \BadMethodCallException(get_class($this) . '::getType() not implemented');
+    }
     return (string) $this->getType() . ':' . $this->getTargetIdentifier();
   }
 
diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon
index 0a143fbb4c7316544f0e8ff9e8df2b01c6ef12f2..4088afbe5fb00814916d36ebd2816bbbc710fd57 100644
--- a/core/phpstan-baseline.neon
+++ b/core/phpstan-baseline.neon
@@ -820,11 +820,6 @@ parameters:
 			count: 1
 			path: lib/Drupal/Core/Theme/ThemeManager.php
 
-		-
-			message: "#^Call to an undefined method Drupal\\\\Core\\\\TypedData\\\\DataReferenceBase\\:\\:getType\\(\\)\\.$#"
-			count: 1
-			path: lib/Drupal/Core/TypedData/DataReferenceBase.php
-
 		-
 			message: "#^Method Drupal\\\\Core\\\\TypedData\\\\ListDataDefinition\\:\\:setDataType\\(\\) should return static\\(Drupal\\\\Core\\\\TypedData\\\\ListDataDefinition\\) but return statement is missing\\.$#"
 			count: 1
diff --git a/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php b/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php
index f1a62beefbd39a5fe041250a2b6d1c24d3dfd297..434d5578ecfc1e143030fb11d85fd9998030811f 100644
--- a/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php
+++ b/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php
@@ -7,6 +7,7 @@
 use Drupal\Core\TypedData\DataDefinitionInterface;
 use Drupal\Core\TypedData\DataReferenceDefinition;
 use Drupal\Core\TypedData\DataReferenceDefinitionInterface;
+use Drupal\Core\TypedData\DataReferenceInterface;
 use Drupal\Core\TypedData\ListDataDefinition;
 use Drupal\Core\TypedData\ListDataDefinitionInterface;
 use Drupal\Core\TypedData\MapDataDefinition;
@@ -99,4 +100,16 @@ public function testDataReferences() {
     $this->assertEquals(serialize($language_reference_definition2), serialize($language_reference_definition));
   }
 
+  /**
+   * Tests getString() throws exception when getType() is not implemented.
+   */
+  public function testNotImplementedGetType() {
+    $language_reference_definition = DataReferenceDefinition::create('language');
+    $language_reference = $this->typedDataManager->create($language_reference_definition);
+    $this->assertInstanceOf(DataReferenceInterface::class, $language_reference);
+    $this->expectException(\BadMethodCallException::class);
+    $this->expectExceptionMessageMatches('/getType\(\) not implemented/');
+    $language_reference->getString();
+  }
+
 }