bag icon indicating copy to clipboard operation
bag copied to clipboard

[Discussion] Create union type from `In` rule

Open chrisk-7777 opened this issue 1 month ago • 0 comments

First, this package rocks 🤘

Btw This can be moved to a discussion, as its not really an issue.

I was wondering if its possible to remove the duplicate here:

#[TypeScript]
#[MapOutputName(CamelCase::class)]
readonly class StoreRequest extends Bag
{
    public function __construct(
        #[Required]
        #[Str]
        #[Max(255)]
        public string $name,

        #[In('website', 'webapp', 'mobileapp', 'desktop_app', 'api')]
        #[LiteralTypeScriptType("'website' | 'webapp' | 'mobileapp' | 'desktop_app' | 'api'")]
        public string $type,

        #[In('a', 'aa', 'aaa')]
        #[LiteralTypeScriptType("'a' | 'aa' | 'aaa'")]
        public Optional|string $compliance_level,
    ) {}
}

This correctly outputs:

    export type StoreProjectRequest = {
        name: string;
        type: "website" | "webapp" | "mobileapp" | "desktop_app" | "api";
        complianceLevel?: "a" | "aa" | "aaa";
    };

Duplicating the union type between In and LiteralTypeScriptType is not the end of the world, just curious if it can be done in one line.

chrisk-7777 avatar Nov 19 '25 11:11 chrisk-7777