When attempting to calculate a virtual property model, I encounter the error message: Object is possibly 'null'. I would prefer not to suppress TypeScript's strict rule if possible.
import { Schema, model } from "mongoose";
const SymbolSchema = new Schema({
max: Number,
min: Number,
});
export interface Symbol {
max: number;
min: number;
}
export default model("Symbol", SymbolSchema);
SymbolSchema.virtual("diff").get(() => {
return this ? (this?.max - this?.min ): 0
// encountering error: Object is possibly 'undefined'.ts(2532)
});
I have also checked this
, but the ts(2532)
error persists. How can this issue be resolved?