Expected 'property' to be of type string, instead found type object - Dynamoose
Schema must be like this :
const ImageGalleryFoldersSchema = new Schema({
key: {
type: String,
hashKey: true,
required: true,
},
displayName: {
type: String,
required: true,
},
parentFolderKey: {
type: String,
required: false,
},
isActive: {
type: Boolean,
default: true,
required: false,
},
}, {
timestamps: true,
});
My guess is that the problem could be related with the name of your attribute, model
.
In fact, this is the actual case: the following code, extracted from the source code in Document.ts
is the one which is overwriting your model
property:
Object.defineProperty(this, "model", {
"configurable": false,
"value": model
});
This is how the Document
looks like before:
And after the execution of the aforementioned code:
This code is executed when processing the Scan
exec
function in DocumentRetriever.ts
when the library maps every Item
returned by DynamoDB to their internal Document
representation, exactly in this line of code:
const array: any = (await Promise.all(result.Items.map(async (item) => await new this.internalSettings.model.Document(item, {"type": "fromDynamo"}).conformToSchema({"customTypesDynamo": true, "checkExpiredItem": true, "saveUnknown": true, "modifiers": ["get"], "type": "fromDynamo"})))).filter((a) => Boolean(a));
The error you reported is a consequence of that change when the type of the returned Item
is checked against your schema model in the checkTypeFunction
:
const {isValidType, matchedTypeDetails, typeDetailsArray} = utils.dynamoose.getValueTypeCheckResult(schema, value, genericKey, settings, {"standardKey": true, typeIndexOptionMap});
if (!isValidType) {
throw new Error.TypeMismatch(`Expected ${key} to be of type ${typeDetailsArray.map((detail) => detail.dynamicName ? detail.dynamicName() : detail.name.toLowerCase()).join(", ")}, instead found type ${typeof value}.`);
...
Please, try a different name, I think it will work properly.