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

269
Vistas
Property 'tableData' does not exist on type 'IPerson' in MaterialTable component

I have a MaterialTable component and I added the editable attribute to it. For onRowUpdate and onRowDelete methods, I want to get the index of the updated or removed item.

This is the minimal reproducible sandbox: https://codesandbox.io/s/busy-fast-z84qq?file=/src/App.tsx

I got the error when I obtained the index of the item. Should I include the tableData property to my IPerson interface? How can I overcome this problem?

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

0

Should I include the tableData property to my IPerson interface?

No, because you will probably use your IPerson interface throughout your application, and adding a tableData property that may or may not exist (see below) will defeat the purpose of typechecking. Typescript is telling you that tableData doesn't exist on your IPerson interface, which is correct. However, the underlying Javascript from your dependency has appended your object with a tableData property for its own internal purposes (and external if this is the only way to get at the index) and didn't bother to let Typescript know. Your code runs, the index is available for use.

There are probably better ways to do this, but you could create an IPersonAfterRowUpdate interface that has the tableData object on it:

interface IPersonAfterRowUpdate extends IPerson {
  tableData: { id: number };
}

/* ... */

onRowUpdate: (newData, oldData) =>
            new Promise<void>((resolve, _reject) => {
              setTimeout(() => {
                if (oldData) {
                  const updatedData = [...data];
                  const index = (oldData as IPersonAfterRowUpdate).tableData.id;
                  updatedData[index] = newData;
                  setData(updatedData);
                  resolve();
                }
                _reject(new Error('Could not find oldData'));
              }, 1000);
            }),

Notice we have to check that oldData exists otherwise TS wouldn't like us indexing updatedData with a possible undefined value.

Then submit a PR to this library with this function typed correctly!

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