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

221
Vistas
How can I define the object type in a returned pipe(map(...)) statement?

I started developing an app in Angular + Ionic Framework.

My problem is that I don't know how to define the type on a returned object to be able to retrieve specific attributes.

I think this is a common problem but I couldn't find the proper results using google.

When I try to return my authentication token from device storage, which looks something like

{
   key:'authData',
   value: token
}

I am not able to compile as my value attribute is not known on the returned storedData field.

error TS2339: Property 'value' does not exist on type 'unknown'.

return from(Storage.get({ key: 'authData' })).pipe(map(storedData => {
  if (!storedData || !storedData.value) {
    return null;
  }
  const parsedData = JSON.parse(storedData.value)
}

So I am looking for some type to define the interface type on the storedData object. Kind regards!

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

0

You must declare a model in the top of your file

interface StoredData {
   key: string;
   value: string;
}

And then later in your code:

return from(Storage.get({ key: 'authData' })).pipe(map(storedData: StoredData => {
  if (!storedData || !storedData.value) {
    return null;
  }
  const parsedData = JSON.parse(storedData.value)
 }

Alternatively you can cheat the linter with:

return from(Storage.get({ key: 'authData' })).pipe(map(storedData => {
  if (!storedData || !storedData['value']) {
    return null;
  }
  const parsedData = JSON.parse(storedData['value'])
 }
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