diff --git a/src/ObjectShapeType.php b/src/ObjectShapeType.php index 74ccd6b..b580800 100644 --- a/src/ObjectShapeType.php +++ b/src/ObjectShapeType.php @@ -12,7 +12,7 @@ final class ObjectShapeType implements Type { /** - * @param array $properties + * @param non-empty-array $properties */ public function __construct( private readonly array $properties, diff --git a/src/TypeVisitor.php b/src/TypeVisitor.php index c63b5b7..8627eba 100644 --- a/src/TypeVisitor.php +++ b/src/TypeVisitor.php @@ -187,7 +187,7 @@ public function object(Type $self): mixed; /** * @param Type $self - * @param array $properties + * @param non-empty-array $properties * @return TReturn */ public function objectShape(Type $self, array $properties): mixed; diff --git a/src/types.php b/src/types.php index 9cbf03c..e834b6d 100644 --- a/src/types.php +++ b/src/types.php @@ -336,6 +336,10 @@ public static function object(string $class, Type ...$templateArguments): Type */ public static function objectShape(array $properties = []): Type { + if ($properties === []) { + return self::object; + } + return new ObjectShapeType(array_map( static fn(Type|Property $property): Property => $property instanceof Type ? new Property($property) : $property, $properties,