Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
TypeScript Argument of type 'IAccount' is not assignable to parameter of type 'never'

I am getting the above error when using the following types:

export interface IAccounts {
    "accounts": Array<IAccount>;
}

export interface IAccount {
  "username": string;
  "assets": Array<any>;
}

I am trying to initialize an account in my JSON file inside of a class constructor:

constructor(username: string) {
        super();
        this.username = username;
        if(!fs.existsSync('db.json')){
            let accountsObj = { "accounts": [] };
            let account: IAccount = {"username": username, "assets": []};
            accountsObj.accounts.push(account); // <-- here is where i am getting the error
            fs.writeFileSync('db.json', JSON.stringify(accountsObj), (err: any) => {
                if(err) {
                    console.log(err);
                }
                else {
                    console.log('************************************************************')
                    console.log(`*  Account successfully created. Welcome, ${this.username}!*`)
                    console.log('************************************************************')
                }
            })
            this.accountsObj = this.getAccountsObject();
            this.account = account;
        }
        else {
            this.accountsObj = this.getAccountsObject();
            this.account = this.getAccount(this.username);
        }
        
        
    }

I have tried to get this to work in multiple ways, I feel like I am missing something in the interface definitions.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to specify the type of accountsObj. Otherwise Typescript will not know the correct type and will asign { accounts: never[] } based on the assigned object to it.

let accountsObj: IAccounts  = { "accounts": [] }

// or

let accountsObj = { "accounts": [] } as IAccounts
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda