From 04be82b15f1d653dd326a49b708fc19aeba64bc0 Mon Sep 17 00:00:00 2001 From: Tristan Zajonc Date: Wed, 6 Dec 2023 09:49:22 -0800 Subject: [PATCH] add types to readme example --- README.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d000ab2..814030d 100644 --- a/README.md +++ b/README.md @@ -76,19 +76,32 @@ type Song = { title: string; }; +type ChargeStatus = { + status: "charged" | "declined"; +}; + +type AccessStatus = { + status: "unlocked" | "locked"; +}; + +type Status = { + charge: ChargeStatus; + access: AccessStatus; +}; + // Purchase song event handler -async function purchase(ctx: Context, user: User, song: Song): Promise<{ charge: any; access: any }> { +async function purchase(ctx: Context, user: User, song: Song): Promise { const charge = await ctx.run(chargeCreditCard, user, song); const access = await ctx.run(unlockUserAccess, user, song); return { charge, access }; } -async function chargeCreditCard(ctx: Context, user: User, song: Song): Promise { +async function chargeCreditCard(ctx: Context, user: User, song: Song): Promise { console.log("Charging credit card..."); return { status: "charged" }; } -async function unlockUserAccess(ctx: Context, user: User, song: Song): Promise { +async function unlockUserAccess(ctx: Context, user: User, song: Song): Promise { console.log("Unlocking user access..."); return { status: "unlocked" }; }