Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

313
Views
type any is not assignedable to type never. (after adding index signature to interface)

hi so i i am getting the follow error for the follow function:

function:

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

errors:

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

the first error is assigned to the word "id" the 2nd is to "active" and the 3rd one is to "createdAt"

my interface to this collection:

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

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

}

apprenatly the problem started happening after i added [key:string]: any (i dont want to delete this). any ideas how to fix this?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This can be simplified to:

interface Stock {
  id: any
  active: any
  createdAt: any
}

interface Foo {
    stocks?: Stock[]
    [key: string]: any
}

const foo: Foo = {
    stocks: [{
        id: 1,
        active: true,
        createdAt: Date.now()
    }]
}

console.log(foo)

According to the playground the basic structure works fine. Your type definition is very liberal and probably not much help, but I imagine that you are working towards narrower type definitions.

I suspect that the problem lies in the implementation of the Mongoose function and how it determines type (which might not be helped by the liberal definition you are giving it).

Adding the accessor type ([key: string]: any) doesn't seem to make any difference to the playground acceptability, and only serves to weaken the property definitions (i.e. stocks is optional of a specified shape, AND it can be any) which might well be messing up Mongoose's interpretation of type. Why do you think you need that accessor definition?

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!