Skip to content

Commit

Permalink
Merge pull request #44 from ragulka/prevent-duplicate-types
Browse files Browse the repository at this point in the history
Ensure transformed types are unique
  • Loading branch information
rubenvanassche authored Feb 1, 2023
2 parents b88bfe6 + 879eda3 commit 218bd31
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Actions/TranspileTypeToTypeScriptAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/FakeClasses/Integration/Dto.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Dto extends DataTransferObject
/** @var int|string */
public $mixed;

/** @var int|float */
public $number;

/** @var int[] */
public $documented_array;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ array: Array<any>;
none: any;
documented_string: string;
mixed: number | string;
number: number;
documented_array: Array<number>;
mixed_with_array: number | string | Array<number | string>;
array_with_null: Array<number | null>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ array: Array<any>;
none: any;
documented_string: string;
mixed: number | string;
number: number;
documented_array: Array<number>;
mixed_with_array: number | string | Array<number | string>;
array_with_null: Array<number | null>;
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/IntegrationTest__it_works__1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ array: Array<any>;
none: any;
documented_string: string;
mixed: number | string;
number: number;
documented_array: Array<number>;
mixed_with_array: number | string | Array<number | string>;
array_with_null: Array<number | null>;
Expand Down

0 comments on commit 218bd31

Please sign in to comment.