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

117
Views
El argumento TypeScript de tipo 'IAccount' no se puede asignar al parámetro de tipo 'nunca'

Recibo el error anterior cuando uso los siguientes tipos:

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

Estoy tratando de inicializar una cuenta en mi archivo JSON dentro de un constructor de clases:

 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); } }

He intentado hacer que esto funcione de varias maneras, siento que me falta algo en las definiciones de la interfaz.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe especificar el tipo de accountsObj . De lo contrario, Typescript no sabrá el tipo correcto y asignará { accounts: never[] } en función del objeto asignado.

 let accountsObj: IAccounts = { "accounts": [] } // or let accountsObj = { "accounts": [] } as IAccounts
about 4 years ago · Juan Pablo Isaza 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!