Skip to content

Comments

Feat: Add return union types support#115

Merged
tcampbPPU merged 3 commits intofumeapp:masterfrom
abetwothree:feature-add-reflection-union-types
Feb 17, 2026
Merged

Feat: Add return union types support#115
tcampbPPU merged 3 commits intofumeapp:masterfrom
abetwothree:feature-add-reflection-union-types

Conversation

@abetwothree
Copy link
Contributor

@abetwothree abetwothree commented Feb 15, 2026

Summary

This PR adds support for return union types. E.g. returning: string|int|null would make the TS file would have string | number | null as the type.

Problem

Previously, having a PHP union return type gets converted to unknown as the return type.

This:

protected function scoreNullable(): Attribute
{
    return Attribute::get(fn (): float|int|null => null);
}

Becomes this:

score_nullable: unknown

That causes some issues in TypeScript code expecting a more properly defined type.

Solution

This PR adds a section to handle when the reflection return type is ReflectionUnionType and loop through each return type to map them to TypeScript

  • src/Actions/WriteColumnAttribute.php

Tests

Tests have been added and updated existing expectations to keep previous tests working.

Thank you!

@tcampbPPU
Copy link
Member

TIL ReflectionUnionType
TY ❤️

@tcampbPPU tcampbPPU merged commit 4617573 into fumeapp:master Feb 17, 2026
12 checks passed
@abetwothree abetwothree deleted the feature-add-reflection-union-types branch February 17, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants