Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

314
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda