From bdbd275ebd9c12ce68748d584404245f1a61da5b Mon Sep 17 00:00:00 2001 From: ragulka Date: Fri, 6 Jan 2023 16:40:15 +0200 Subject: [PATCH] ensure transformed types are unique --- src/Actions/TranspileTypeToTypeScriptAction.php | 2 +- tests/FakeClasses/Integration/Dto.php | 3 +++ .../DtoTransformerTest__it_will_replace_types__1.txt | 1 + .../IntegrationTest__it_can_transform_to_es_modules__1.txt | 1 + tests/__snapshots__/IntegrationTest__it_works__1.txt | 1 + 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Actions/TranspileTypeToTypeScriptAction.php b/src/Actions/TranspileTypeToTypeScriptAction.php index d7123b4..09204f7 100644 --- a/src/Actions/TranspileTypeToTypeScriptAction.php +++ b/src/Actions/TranspileTypeToTypeScriptAction.php @@ -66,7 +66,7 @@ private function resolveCompoundType(Compound $compound): string iterator_to_array($compound->getIterator()) ); - return join(' | ', $transformed); + return join(' | ', array_unique($transformed)); } private function resolveListType(AbstractList $list): string diff --git a/tests/FakeClasses/Integration/Dto.php b/tests/FakeClasses/Integration/Dto.php index d681f53..0b70a39 100644 --- a/tests/FakeClasses/Integration/Dto.php +++ b/tests/FakeClasses/Integration/Dto.php @@ -34,6 +34,9 @@ class Dto extends DataTransferObject /** @var int|string */ public $mixed; + /** @var int|float */ + public $number; + /** @var int[] */ public $documented_array; diff --git a/tests/__snapshots__/DtoTransformerTest__it_will_replace_types__1.txt b/tests/__snapshots__/DtoTransformerTest__it_will_replace_types__1.txt index 2c58855..7528c1f 100644 --- a/tests/__snapshots__/DtoTransformerTest__it_will_replace_types__1.txt +++ b/tests/__snapshots__/DtoTransformerTest__it_will_replace_types__1.txt @@ -10,6 +10,7 @@ array: Array; none: any; documented_string: string; mixed: number | string; +number: number; documented_array: Array; mixed_with_array: number | string | Array; array_with_null: Array; diff --git a/tests/__snapshots__/IntegrationTest__it_can_transform_to_es_modules__1.txt b/tests/__snapshots__/IntegrationTest__it_can_transform_to_es_modules__1.txt index 3315c7d..1488b8e 100644 --- a/tests/__snapshots__/IntegrationTest__it_can_transform_to_es_modules__1.txt +++ b/tests/__snapshots__/IntegrationTest__it_can_transform_to_es_modules__1.txt @@ -10,6 +10,7 @@ array: Array; none: any; documented_string: string; mixed: number | string; +number: number; documented_array: Array; mixed_with_array: number | string | Array; array_with_null: Array; diff --git a/tests/__snapshots__/IntegrationTest__it_works__1.txt b/tests/__snapshots__/IntegrationTest__it_works__1.txt index 87457b9..f6f0669 100644 --- a/tests/__snapshots__/IntegrationTest__it_works__1.txt +++ b/tests/__snapshots__/IntegrationTest__it_works__1.txt @@ -11,6 +11,7 @@ array: Array; none: any; documented_string: string; mixed: number | string; +number: number; documented_array: Array; mixed_with_array: number | string | Array; array_with_null: Array;