mongoose + typescript schema/interface (problem with $push and Array of object interface)

Viewed 67

so basically i have 2 problems:

first is im getting this error:

Type instantiation is excessively deep and possibly infinite.

on all the items inside the schema. this actually does not prevent from the schema to work however it might be part of the bigger problem and anyways its a problem i would like to get rid off.

the bigger problem is that im getting these errors:

error TS2322: Type 'any' is not assignable to type 'never'.
error TS2322: Type 'boolean' is not assignable to type 'never'.
error TS2322: Type 'number' is not assignable to type 'never'.

which wont let me compile without using @ts-expect-error above the function that cause the problem.

this is the function that trigger the problem:

        await AutoUsersPositions.updateOne(
            { user: userSetup.userEmail },
            { $push: { stocks: { id: position._id, active: true, createdAt: Date.now() } } }
        )

the problem is being triggered by the keys "id" ,"active" and "createdAt".

this is the full schema and interface:

import {Document, model, Schema, Types } from "mongoose";

export interface optionsArray extends Document{
    id: any, 
    active: Boolean, 
    createdAt: Number
}


export interface AutoUsersPositionsDocument extends Document {
    user?: string,
    userID?: string,
    stocks?: [optionsArray],
    bonds?: [optionsArray],
    comodity?: [optionsArray],
    currencyPairs?: [optionsArray],
    indexes?: [optionsArray],
    [key: string]: any

}

const AutoUsersPositionSchema = new Schema({ //סכמה משתמש
    user: String, 
    userID: String,
    stocks:  [Schema.Types.Mixed],
    bonds: [Schema.Types.Mixed],
    comodity: [Schema.Types.Mixed],
    currencyPairs: [Schema.Types.Mixed],
    indexes: [Schema.Types.Mixed],
}, { collection: "AutoUsersPositions"} );

const AutoUsersPositions = model<AutoUsersPositionsDocument>("AutoUsersPositions", AutoUsersPositionSchema);
export default AutoUsersPositions;

any idea what can cause the problem? by the way the 2nd problem started happening after adding the index signature: [key:string]: any but i need this index signature for dynamic option

0 Answers
Related