diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/BooleanData.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/BooleanData.php
index 1583c79bd7..cfe0b78797 100644
--- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/BooleanData.php
+++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/BooleanData.php
@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types = 1);
+
 namespace Drupal\Core\TypedData\Plugin\DataType;
 
 use Drupal\Core\TypedData\PrimitiveBase;
@@ -21,8 +23,8 @@ class BooleanData extends PrimitiveBase implements BooleanInterface {
   /**
    * {@inheritdoc}
    */
-  public function getCastedValue() {
-    return (bool) $this->value;
+  public function getValue(): ?bool {
+    return $this->value !== NULL ? (bool) $this->value : NULL;
   }
 
 }
diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/FloatData.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/FloatData.php
index 4de7e18b22..48ad3b5e4d 100644
--- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/FloatData.php
+++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/FloatData.php
@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types = 1);
+
 namespace Drupal\Core\TypedData\Plugin\DataType;
 
 use Drupal\Core\TypedData\PrimitiveBase;
@@ -21,8 +23,8 @@ class FloatData extends PrimitiveBase implements FloatInterface {
   /**
    * {@inheritdoc}
    */
-  public function getCastedValue() {
-    return (float) $this->value;
+  public function getValue(): ?float {
+    return $this->value !== NULL ? (float) $this->value : NULL;
   }
 
 }
diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/IntegerData.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/IntegerData.php
index 8421dcaf2f..02b5de8f3e 100644
--- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/IntegerData.php
+++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/IntegerData.php
@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types = 1);
+
 namespace Drupal\Core\TypedData\Plugin\DataType;
 
 use Drupal\Core\TypedData\PrimitiveBase;
@@ -21,8 +23,8 @@ class IntegerData extends PrimitiveBase implements IntegerInterface {
   /**
    * {@inheritdoc}
    */
-  public function getCastedValue() {
-    return (int) $this->value;
+  public function getValue(): ?int {
+    return $this->value !== NULL ? (int) $this->value : NULL;
   }
 
 }
diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/StringData.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/StringData.php
index 270f116257..37eb699f61 100644
--- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/StringData.php
+++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/StringData.php
@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types = 1);
+
 namespace Drupal\Core\TypedData\Plugin\DataType;
 
 use Drupal\Core\TypedData\PrimitiveBase;
@@ -21,8 +23,8 @@ class StringData extends PrimitiveBase implements StringInterface {
   /**
    * {@inheritdoc}
    */
-  public function getCastedValue() {
-    return $this->getString();
+  public function getValue(): ?string {
+    return $this->value !== NULL ? (string) $this->value : NULL;
   }
 
 }
diff --git a/core/lib/Drupal/Core/TypedData/PrimitiveBase.php b/core/lib/Drupal/Core/TypedData/PrimitiveBase.php
index ac2d1c130b..bcca12f7d0 100644
--- a/core/lib/Drupal/Core/TypedData/PrimitiveBase.php
+++ b/core/lib/Drupal/Core/TypedData/PrimitiveBase.php
@@ -32,4 +32,11 @@ public function setValue($value, $notify = TRUE) {
     }
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function getCastedValue() {
+    return $this->getValue();
+  }
+
 }
