fix: replace any types with proper types across codebase
Replace ~100 `any` usages with proper types: use existing interfaces (RecipeModelType, BriefRecipeType, IPayment, etc.), Record<string, unknown> for dynamic objects, unknown for catch clauses with proper narrowing, and inline types for callbacks. Remaining `any` types are in Svelte components and cases where mongoose document mutation requires casts.
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
// Utility functions for identifying and handling settlement payments
|
||||
|
||||
import type { IPayment } from '$models/Payment';
|
||||
import type { IPaymentSplit } from '$models/PaymentSplit';
|
||||
|
||||
type PaymentWithSplits = IPayment & { splits?: IPaymentSplit[] };
|
||||
|
||||
/**
|
||||
* Identifies if a payment is a settlement payment based on category
|
||||
*/
|
||||
export function isSettlementPayment(payment: any): boolean {
|
||||
export function isSettlementPayment(payment: PaymentWithSplits | null | undefined): boolean {
|
||||
if (!payment) return false;
|
||||
|
||||
|
||||
// Check if category is settlement
|
||||
return payment.category === 'settlement';
|
||||
}
|
||||
@@ -20,44 +25,44 @@ export function getSettlementIcon(): string {
|
||||
/**
|
||||
* Gets appropriate styling classes for settlement payments
|
||||
*/
|
||||
export function getSettlementClasses(payment: any): string[] {
|
||||
export function getSettlementClasses(payment: PaymentWithSplits): string[] {
|
||||
if (!isSettlementPayment(payment)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
return ['settlement-payment'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets settlement-specific display text
|
||||
*/
|
||||
export function getSettlementDisplayText(payment: any): string {
|
||||
export function getSettlementDisplayText(payment: PaymentWithSplits): string {
|
||||
if (!isSettlementPayment(payment)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
return 'Settlement';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the other user in a settlement (the one who didn't pay)
|
||||
*/
|
||||
export function getSettlementReceiver(payment: any): string {
|
||||
export function getSettlementReceiver(payment: PaymentWithSplits): string {
|
||||
if (!isSettlementPayment(payment) || !payment.splits) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
// Find the user who has a positive amount (the receiver)
|
||||
const receiver = payment.splits.find((split: any) => split.amount > 0);
|
||||
const receiver = payment.splits.find((split) => split.amount > 0);
|
||||
if (receiver && receiver.username) {
|
||||
return receiver.username;
|
||||
}
|
||||
|
||||
|
||||
// Fallback: find the user who is not the payer
|
||||
const otherUser = payment.splits.find((split: any) => split.username !== payment.paidBy);
|
||||
const otherUser = payment.splits.find((split) => split.username !== payment.paidBy);
|
||||
if (otherUser && otherUser.username) {
|
||||
return otherUser.username;
|
||||
}
|
||||
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user