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:
@@ -175,6 +175,8 @@ const RecipeSchema = new mongoose.Schema(
|
||||
RecipeSchema.index({ "translations.en.short_name": 1 });
|
||||
RecipeSchema.index({ "translations.en.translationStatus": 1 });
|
||||
|
||||
let _recipeModel: any;
|
||||
try { _recipeModel = mongoose.model("Recipe"); } catch { _recipeModel = mongoose.model("Recipe", RecipeSchema); }
|
||||
export const Recipe = _recipeModel as mongoose.Model<any>;
|
||||
import type { RecipeModelType } from '$types/types';
|
||||
|
||||
let _recipeModel: mongoose.Model<RecipeModelType>;
|
||||
try { _recipeModel = mongoose.model<RecipeModelType>("Recipe"); } catch { _recipeModel = mongoose.model<RecipeModelType>("Recipe", RecipeSchema); }
|
||||
export const Recipe = _recipeModel;
|
||||
|
||||
@@ -93,7 +93,7 @@ const RecurringPaymentSchema = new mongoose.Schema(
|
||||
cronExpression: {
|
||||
type: String,
|
||||
validate: {
|
||||
validator: function(this: any, value: string) {
|
||||
validator: function(this: IRecurringPayment, value: string) {
|
||||
// Only validate if frequency is custom
|
||||
if (this.frequency === 'custom') {
|
||||
return value != null && value.trim().length > 0;
|
||||
|
||||
@@ -9,7 +9,12 @@ const RosaryStreakSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let _model: any;
|
||||
try { _model = mongoose.model("RosaryStreak"); } catch { _model = mongoose.model("RosaryStreak", RosaryStreakSchema); }
|
||||
export const RosaryStreak = _model as mongoose.Model<any>;
|
||||
interface IRosaryStreak {
|
||||
username: string;
|
||||
length: number;
|
||||
lastPrayed: string | null;
|
||||
}
|
||||
|
||||
let _model: mongoose.Model<IRosaryStreak>;
|
||||
try { _model = mongoose.model<IRosaryStreak>("RosaryStreak"); } catch { _model = mongoose.model<IRosaryStreak>("RosaryStreak", RosaryStreakSchema); }
|
||||
export const RosaryStreak = _model;
|
||||
|
||||
Reference in New Issue
Block a user