Skip to content

Commit 879b270

Browse files
authored
add types to readme example (#9)
1 parent 5576004 commit 879b270

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

README.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,32 @@ type Song = {
7676
title: string;
7777
};
7878

79+
type ChargeStatus = {
80+
status: "charged" | "declined";
81+
};
82+
83+
type AccessStatus = {
84+
status: "unlocked" | "locked";
85+
};
86+
87+
type Status = {
88+
charge: ChargeStatus;
89+
access: AccessStatus;
90+
};
91+
7992
// Purchase song event handler
80-
async function purchase(ctx: Context, user: User, song: Song): Promise<{ charge: any; access: any }> {
93+
async function purchase(ctx: Context, user: User, song: Song): Promise<Status> {
8194
const charge = await ctx.run(chargeCreditCard, user, song);
8295
const access = await ctx.run(unlockUserAccess, user, song);
8396
return { charge, access };
8497
}
8598

86-
async function chargeCreditCard(ctx: Context, user: User, song: Song): Promise<any> {
99+
async function chargeCreditCard(ctx: Context, user: User, song: Song): Promise<ChargeStatus> {
87100
console.log("Charging credit card...");
88101
return { status: "charged" };
89102
}
90103

91-
async function unlockUserAccess(ctx: Context, user: User, song: Song): Promise<any> {
104+
async function unlockUserAccess(ctx: Context, user: User, song: Song): Promise<AccessStatus> {
92105
console.log("Unlocking user access...");
93106
return { status: "unlocked" };
94107
}

0 commit comments

Comments
 (0)