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

323
Views
type any no se puede asignar a type never. (después de agregar la firma de índice a la interfaz)

hola, estoy recibiendo el siguiente error para la siguiente función:

función:

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

errores:

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

el primer error se asigna a la palabra "id", el segundo es "activo" y el tercero es "creado en"

mi interfaz para esta colección:

 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 }

Aparentemente, el problema comenzó a ocurrir después de que agregué [key:string]: any (no quiero eliminar esto). ¿Alguna idea de cómo solucionar este problema?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto se puede simplificar a:

 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)

Según el patio de recreo , la estructura básica funciona bien. Su definición de tipo es muy liberal y probablemente no sea de mucha ayuda, pero imagino que está trabajando para lograr definiciones de tipo más estrechas.

Sospecho que el problema radica en la implementación de la función Mongoose y cómo determina el tipo (que podría no ser ayudado por la definición liberal que le está dando).

Agregar el tipo de acceso ( [key: string]: any ) no parece hacer ninguna diferencia en la aceptabilidad del patio de recreo, y solo sirve para debilitar las definiciones de propiedad (es decir, stocks son opcionales de una forma específica, Y puede ser cualquiera) lo que bien podría estar estropeando la interpretación de tipo de Mongoose. ¿Por qué crees que necesitas esa definición de acceso?

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!