Skip to content

Commit

Permalink
non-empty array of properties in object shape
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Feb 24, 2024
1 parent baa8a79 commit dc8f72f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ObjectShapeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
final class ObjectShapeType implements Type
{
/**
* @param array<string, Property> $properties
* @param non-empty-array<string, Property> $properties
*/
public function __construct(
private readonly array $properties,
Expand Down
2 changes: 1 addition & 1 deletion src/TypeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function object(Type $self): mixed;

/**
* @param Type<object> $self
* @param array<string, Property> $properties
* @param non-empty-array<string, Property> $properties
* @return TReturn
*/
public function objectShape(Type $self, array $properties): mixed;
Expand Down
4 changes: 4 additions & 0 deletions src/types.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dc8f72f

Please sign in to comment.