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

121
Vistas
Specifying Typescript return type that implements interface with additional fields

So I have a function that returns an object which extends the FooInterface class. I want to restrict the return type to classes that implement FooInterface but also have an additional field.

interface FooInterface {
   readonly banana: string
}

function doThing() : FooInterface {

    return { 
        banana: 'blah',
        additionalField: 'blah2', // Must have
    }
}

How can I define the return type of doThing() to specify that additionalField be included? If there a way to do this just using the function definition?

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

0

Is this what you need?

function doThing() : FooInterface & { additionalField: string } {
    return { 
        banana: 'blah',
        additionalField: 'blah2', // Must have
    }
}
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