diff --git a/compiler/pdecobj.pas b/compiler/pdecobj.pas
index 0a55bc1c289173a46cc770710e5f8c74fa32d2d0..69d977bed620d53f423394eb9054167ca889a2d1 100644
--- a/compiler/pdecobj.pas
+++ b/compiler/pdecobj.pas
@@ -730,11 +730,22 @@                   childof:=class_tobject;
         end;
 
       procedure check_inheritance_record_type_helper(var def:tdef);
+        var
+          tmp : tstoreddef;
         begin
           if (def.typ<>errordef) and assigned(current_objectdef.childof) then
             begin
               if def<>current_objectdef.childof.extendeddef then
                 begin
+                  { a type helper may extend a type alias of the type its
+                    parent type helper extends }
+                  tmp:=tstoreddef(def);
+                  while (df_unique in tmp.defoptions) and assigned(tstoreddef(tmp).orgdef) do
+                    begin
+                      if tmp.orgdef=current_objectdef.childof.extendeddef then
+                        exit;
+                      tmp:=tstoreddef(tmp.orgdef);
+                    end;
                   Message1(type_e_record_helper_must_extend_same_record,current_objectdef.childof.extendeddef.typename);
                   def:=generrordef;
                 end;
diff --git a/tests/test/tthlp30.pp b/tests/test/tthlp30.pp
new file mode 100644
index 0000000000000000000000000000000000000000..ee5b809523cd87c99ac0af247607e0f656385092
--- /dev/null
+++ b/tests/test/tthlp30.pp
@@ -0,0 +1,72 @@
+program tthlp30;
+
+{$mode objfpc}
+{$modeswitch typehelpers}
+
+type
+  Test1 = type LongInt;
+  Test2 = type LongInt;
+  Test3 = type Test1;
+
+  TLongIntHelper = type helper for LongInt
+    function TestA: LongInt;
+    function TestB: LongInt;
+  end;
+
+  TTest1Helper = type helper(TLongIntHelper) for Test1
+    function TestA: LongInt;
+  end;
+
+  TTest2Helper = type helper(TLongIntHelper) for Test2
+    function TestB: LongInt;
+  end;
+
+  TTest3Helper = type helper(TLongIntHelper) for Test3
+  end;
+
+function TTest2Helper.TestB: LongInt;
+begin
+  Result := 2;
+end;
+
+function TTest1Helper.TestA: LongInt;
+begin
+  Result := 2;
+end;
+
+function TLongIntHelper.TestA: LongInt;
+begin
+  Result := 1;
+end;
+
+function TLongIntHelper.TestB: LongInt;
+begin
+  Result := 1;
+end;
+
+var
+  l: LongInt;
+  t1: Test1;
+  t2: Test2;
+  t3: Test3;
+begin
+  if l.TestA <> 1 then
+    Halt(1);
+  if l.TestB <> 1 then
+    Halt(2);
+
+  if t1.TestA <> 2 then
+    Halt(3);
+  if t1.TestB <> 1 then
+    Halt(4);
+
+  if t2.TestA <> 1 then
+    Halt(5);
+  if t2.TestB <> 2 then
+    Halt(6);
+
+  if t3.TestA <> 1 then
+    Halt(7);
+  if t3.TestB <> 1 then
+    Halt(8);
+end.
diff --git a/tests/test/tthlp31.pp b/tests/test/tthlp31.pp
new file mode 100644
index 0000000000000000000000000000000000000000..4df48f2b6c8419b8fe09c5e6efff605fb0c49134
--- /dev/null
+++ b/tests/test/tthlp31.pp
@@ -0,0 +1,19 @@
+{ %FAIL }
+
+program tthlp31;
+
+{$mode objfpc}
+{$modeswitch typehelpers}
+
+type
+  Test = type LongInt;
+
+  TTestHelper = type helper for Test
+  end;
+
+  TLongIntHelper = type helper(TTestHelper) for LongInt
+  end;
+
+begin
+
+end.