If I have a schema that includes fields that may or may not be set, what is the best way to handle these fields? Should they be optional or instead nullable?
Here an example (Mongoose/NestJs)
@Schema()
class MySchema {
@Prop({ required: true )
classification: string;
@Prop({ default: null })
nullableProperty: string | null;
@Prop()
optionalProperty?: string;
}
Is one way always better than the other or are there some guidelines, which option may be better in certain situations?
New contributor
KorbenDose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.