Skip to content

Commit 28923bc

Browse files
committed
refactor: clean up ugly type casting patterns in billing package
- Replace `as unknown as` double-casts with cleaner alternatives: - balance-calculator.ts: use .then() handler for type assertion - credit-delegation.ts: use .then() handler for type assertion - grant-credits.ts: use direct type assertion (limit() returns sync) - All billing files now use consistent, cleaner type patterns
1 parent 2eb1bd9 commit 28923bc

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

packages/billing/src/balance-calculator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ export async function calculateUsageThisCycle(params: {
715715
),
716716
),
717717
),
718-
) as unknown as { totalUsed: number }[]
718+
)
719+
.then(rows => rows as { totalUsed: number }[])
719720

720721
return usageResult[0].totalUsed
721722
}

packages/billing/src/credit-delegation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export async function findOrganizationForRepository(params: {
7171
})
7272
.from(schema.orgMember)
7373
.innerJoin(schema.org, eq(schema.orgMember.org_id, schema.org.id))
74-
.where(eq(schema.orgMember.user_id, userId)) as unknown as { orgId: string; orgName: string; orgSlug: string }[]
74+
.where(eq(schema.orgMember.user_id, userId))
75+
.then(rows => rows as { orgId: string; orgName: string; orgSlug: string }[])
7576

7677
if (userOrganizations.length === 0) {
7778
logger.debug(
@@ -95,7 +96,8 @@ export async function findOrganizationForRepository(params: {
9596
eq(schema.orgRepo.org_id, userOrg.orgId),
9697
eq(schema.orgRepo.is_active, true),
9798
),
98-
) as unknown as { repoUrl: string; repoName: string; isActive: boolean }[]
99+
)
100+
.then(rows => rows as { repoUrl: string; repoName: string; isActive: boolean }[])
99101

100102
// Check if any repository in this organization matches
101103
for (const orgRepo of orgRepos) {

packages/billing/src/grant-credits.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function getPreviousFreeGrantAmount(params: {
5555
),
5656
)
5757
.orderBy(desc(schema.creditLedger.expires_at)) // Most recent expiry first
58-
.limit(1) as unknown as { principal: number }[]
58+
.limit(1) as { principal: number }[]
5959

6060
if (lastExpiredFreeGrant.length > 0) {
6161
// TODO: remove this once it's past May 22nd, after all users have been migrated over
@@ -107,7 +107,7 @@ export async function calculateTotalReferralBonus(params: {
107107
eq(schema.referral.referrer_id, userId),
108108
eq(schema.referral.referred_id, userId),
109109
),
110-
) as unknown as { totalCredits: string }[]
110+
) as { totalCredits: string }[]
111111

112112
const totalBonus = parseInt(result[0]?.totalCredits ?? '0')
113113
logger.debug({ userId, totalBonus }, 'Calculated total referral bonus.')

0 commit comments

Comments
 (0)