14 public readonly array $types,
17 public function stringify(
int $depth = 0) : string{
18 if(count($this->types) === 2){
20 foreach($this->types as $k => $type){
21 if($type instanceof
NamedType && $type->type === BuiltInType::NULL){
22 $types = $this->types;
24 $remaining = array_shift($types);
25 assert($remaining !==
null);
26 return '?' . $remaining->stringify($depth + 1);
31 $result = implode(
'|', array_map(fn($type) => $type->stringify($depth + 1), $this->types));
32 return $depth === 0 ? $result :
"($result)";