Skip to content

Commit

Permalink
Fix pseudo types
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Jul 5, 2023
1 parent af3aca5 commit c976bd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Actions/TranspileTypeToTypeScriptAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}")
};
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Actions/TranspileTypeToTypeScriptActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit c976bd0

Please sign in to comment.