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

244
Views
Error semántico de matriz de mecanografiado TS2532: el objeto posiblemente está 'indefinido'

// Estoy usando Typescript 4.4.4 y node.js 12 LTS para este proyecto, la clase Matrix me está dando un problema durante la compilación con resumen, no estoy seguro de por qué, todo me parece bien

Error:/src/Matrix.ts(29,9): error semántico TS2532: el objeto posiblemente sea 'indefinido'.

El código fuente:

 export class Matrix { rows: number; cols: number; data: number[][]; constructor(rows: number, cols: number) { this.rows = rows; this.cols = cols; this.data = Array(this.rows) .fill(1) .map(() => Array(this.cols).fill(0)); } copy() { const m = new Matrix(this.rows, this.cols); for (let i = 0; i < this.rows; i++) { for (let j = 0; j < this.cols; j++) { m.data[i][j] = this.data[i][j]; } } return m; } ... }

esta es la linea con el error:

 m.data[i][j] = this.data[i][j];

y:

 m.data[i][j] = this?.data?.[i]?.[j] as number;

parecía deshacerse del subrayado rojo en el lado derecho, pero no funciona en el lado izquierdo

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

0

usar ! porque i'm sure, typescript, you don't need to check undefined

 m.data[i]![j]! = this.data[i]![j]!;

tiene esta advertencia debido a la configuración de noUncheckedIndexedAccess tsconfig : https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess

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!