diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php
index 36ff68b..155246d 100644
--- a/core/lib/Drupal/Core/Config/TypedConfigManager.php
+++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php
@@ -170,12 +170,11 @@ protected function getDefinitionWithReplacements($base_plugin_id, array $replace
 
       // Replace dynamic portions of the definition type.
       if (!empty($replacements) && strpos($definition['type'], ']')) {
-        $sub_type = $this->determineType($this->replaceName($definition['type'], $replacements), $definitions);
+        $type = $this->determineType($this->replaceName($definition['type'], $replacements), $definitions);
         // Merge the newly determined subtype definition with the original
         // definition.
-        $definition = NestedArray::mergeDeepArray([$definitions[$sub_type], $definition], TRUE);
+        $definition = NestedArray::mergeDeepArray([$definitions[$type], $definition], TRUE);
       }
-
       // Unset type so we try the merge only once per type.
       unset($definition['type']);
       $this->definitions[$type] = $definition;
diff --git a/core/modules/config/src/Tests/ConfigSchemaTest.php b/core/modules/config/src/Tests/ConfigSchemaTest.php
index 74e543b..56fe862 100644
--- a/core/modules/config/src/Tests/ConfigSchemaTest.php
+++ b/core/modules/config/src/Tests/ConfigSchemaTest.php
@@ -546,8 +546,40 @@ public function testConfigSaveWithWrappingSchemaDoubleBrackets() {
       'tests' => [
         [
           'wrapper_value' => 'foo',
+          'foo' => 'turtle',
+          'bar' => 'horse',
+          // Converted to a string by 'test.double_brackets.turtle.horse'
+          // schema.
+          'another_key' => '100',
+        ],
+      ],
+    ];
+
+    $typed_values = [
+      'tests' => [
+        [
+          'wrapper_value' => 'foo',
+          'foo' => 'turtle',
+          'bar' => 'horse',
+          'another_key' => 100,
+        ],
+      ],
+    ];
+
+    // Save config which has a schema that enforces types.
+    \Drupal::configFactory()->getEditable('wrapping.config_schema_test.double_brackets')
+      ->setData($untyped_values)
+      ->save();
+    $this->assertIdentical(\Drupal::config('wrapping.config_schema_test.double_brackets')
+      ->get(), $typed_values);
+
+    $untyped_values = [
+      'tests' => [
+        [
+          'wrapper_value' => 'foo',
           'foo' => 'cat',
           'bar' => 'dog',
+          // Converted to a string by 'test.double_brackets.cat.dog' schema.
           'another_key' => 100,
         ],
       ],
diff --git a/core/modules/config/tests/config_schema_test/config/schema/config_schema_test.schema.yml b/core/modules/config/tests/config_schema_test/config/schema/config_schema_test.schema.yml
index d7ec9a5..f96bb8b 100644
--- a/core/modules/config/tests/config_schema_test/config/schema/config_schema_test.schema.yml
+++ b/core/modules/config/tests/config_schema_test/config/schema/config_schema_test.schema.yml
@@ -258,5 +258,15 @@ test.double_brackets.cat.dog:
     bar:
       type: string
 
+test.double_brackets.turtle.horse:
+  type: test.double_brackets
+  mapping:
+    another_key:
+      type: integer
+    foo:
+      type: string
+    bar:
+      type: string
+
 test.double_brackets.*:
   type: mapping
