bag
bag copied to clipboard
[Discussion] Create union type from `In` rule
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.