From c976bd05a3acf5dfc555098acb135db1c8648ad4 Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Wed, 5 Jul 2023 14:34:06 +0200 Subject: [PATCH] Fix pseudo types --- src/Actions/TranspileTypeToTypeScriptAction.php | 2 ++ tests/Actions/TranspileTypeToTypeScriptActionTest.php | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/Actions/TranspileTypeToTypeScriptAction.php b/src/Actions/TranspileTypeToTypeScriptAction.php index 87b2ebd..c31f6df 100644 --- a/src/Actions/TranspileTypeToTypeScriptAction.php +++ b/src/Actions/TranspileTypeToTypeScriptAction.php @@ -3,6 +3,7 @@ namespace Spatie\TypeScriptTransformer\Actions; use Exception; +use phpDocumentor\Reflection\PseudoType; use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Types\AbstractList; use phpDocumentor\Reflection\Types\Boolean; @@ -57,6 +58,7 @@ public function execute(Type $type): string $type instanceof Scalar => 'string|number|boolean', $type instanceof Mixed_ => 'any', $type instanceof Void_ => 'void', + $type instanceof PseudoType => $this->execute($type->underlyingType()), default => throw new Exception("Could not transform type: {$type}") }; } diff --git a/tests/Actions/TranspileTypeToTypeScriptActionTest.php b/tests/Actions/TranspileTypeToTypeScriptActionTest.php index 55db7f1..0fa2356 100644 --- a/tests/Actions/TranspileTypeToTypeScriptActionTest.php +++ b/tests/Actions/TranspileTypeToTypeScriptActionTest.php @@ -56,3 +56,9 @@ assertContains(RegularEnum::class, $this->missingSymbols->all()); assertContains('fake_class', $this->missingSymbols->all()); }); + +it('can resolve pseudo types', function (){ + $transformed = $this->action->execute($this->typeResolver->resolve('array-key')); + + expect($transformed)->toBe('string | number'); +});