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:
2026-03-02 20:14:51 +01:00
parent b83d793f61
commit 19e46b2b3a
37 changed files with 236 additions and 146 deletions
+11 -9
View File
@@ -5,6 +5,8 @@
* for SvelteKit form actions with progressive enhancement support.
*/
import type { IngredientItem, InstructionItem, TranslatedRecipeType, TranslationMetadata } from '$types/types';
export interface RecipeFormData {
// Basic fields
name: string;
@@ -22,8 +24,8 @@ export interface RecipeFormData {
note?: string;
// Complex nested structures
ingredients: any[];
instructions: any[];
ingredients: IngredientItem[];
instructions: InstructionItem[];
// Additional info
add_info: {
@@ -65,9 +67,9 @@ export interface RecipeFormData {
// Translation data (optional)
translations?: {
en?: any;
en?: TranslatedRecipeType;
};
translationMetadata?: any;
translationMetadata?: TranslationMetadata;
}
/**
@@ -112,7 +114,7 @@ export function extractRecipeFromFormData(formData: FormData): RecipeFormData {
const note = formData.get('note')?.toString();
// Complex nested structures (JSON-encoded)
let ingredients: any[] = [];
let ingredients: IngredientItem[] = [];
const ingredientsData = formData.get('ingredients_json')?.toString();
if (ingredientsData) {
try {
@@ -122,7 +124,7 @@ export function extractRecipeFromFormData(formData: FormData): RecipeFormData {
}
}
let instructions: any[] = [];
let instructions: InstructionItem[] = [];
const instructionsData = formData.get('instructions_json')?.toString();
if (instructionsData) {
try {
@@ -265,7 +267,7 @@ export function validateRecipeData(data: RecipeFormData): string[] {
* Detects which fields have changed between two recipe objects
* Used for edit forms to enable partial translation updates
*/
export function detectChangedFields(original: any, current: any): string[] {
export function detectChangedFields(original: Record<string, unknown>, current: Record<string, unknown>): string[] {
const changedFields: string[] = [];
// Simple field comparison
@@ -347,8 +349,8 @@ export function parseSeasonData(formData: FormData): number[] {
* Serializes complex recipe data for storage
* Ensures all required fields are present and properly typed
*/
export function serializeRecipeForDatabase(data: RecipeFormData): any {
const recipe: any = {
export function serializeRecipeForDatabase(data: RecipeFormData): Record<string, unknown> {
const recipe: Record<string, unknown> = {
name: data.name,
short_name: data.short_name,
description: data.description,
+2 -2
View File
@@ -459,8 +459,8 @@ class DeepLTranslationService {
const changed: string[] = [];
for (const field of fieldsToCheck) {
const oldValue = JSON.stringify((oldRecipe as any)[field] || '');
const newValue = JSON.stringify((newRecipe as any)[field] || '');
const oldValue = JSON.stringify(oldRecipe[field as keyof RecipeModelType] || '');
const newValue = JSON.stringify(newRecipe[field as keyof RecipeModelType] || '');
if (oldValue !== newValue) {
changed.push(field);
}