Closed NelsonFrancisco closed 2 years ago
Thanks for submitting and providing all the details. Definitely just an edge case of Mongoose syntax that isn't handled. Ill try to get to this over the weekend but might be a bit busy.
If you need this to be functional before then, I think removing default: {}
would fix the problem (although you would need to set it manually then).
I cannot change the Schema. Lots of dependencies on it right now.
I just added @ts-ignore, which I hope to be temporary.
Apologies for the delay here I've been quite busy, hoping to get to this soon!
Hey @NelsonFrancisco , apologies for the delay.
I think the generator is actually correct in this case, {}
is not an allowed value for a document (in your case the field booleanGroup
). You can fix this by instantiating a document using a BooleanGroupModel
:
import mongoose from 'mongoose';
import {
TestDocument,
TestModel,
TestSchema,
BooleanGroupDocument,
BooleanGroupModel,
BooleanGroupSchema
} from '../../../interfaces/mongoose.gen';
const { Schema } = mongoose;
const booleanGroupSchema: BooleanGroupSchema = new Schema(
{
editSignature: Boolean,
editStatement: Boolean,
reviewTemplates: Boolean,
},
{ _id: false },
);
const testSchema: TestSchema = new Schema(
{
_id: { type: String },
booleanGroup: {
type: booleanGroupSchema,
default: () => new BooleanGroup({}),
},
},
{ timestamps: true },
);
const Test: TestModel =
mongoose.models.Test ||
mongoose.model<TestDocument, TestModel>('Test', testSchema);
export const BooleanGroup: BooleanGroupModel =
mongoose.models.Boolean ||
mongoose.model<BooleanGroupDocument, BooleanGroupModel>('BooleanGroup', booleanGroupSchema);
export default Test;
@NelsonFrancisco Have you had a chance to review the previous answer? Would like to close this off if your issue is resolved
Closing this off, feel free to re-open if there is any issues still
Here's a failing snippet:
The complete ts error is:
I cannot figure out. Looks like it lacks some properties
Here's the result of the generation: