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

125
Vistas
Function to wrap function and provide one property of object

I want to create a new function from an initial function, with the initial function taking a single object argument and the new function taking the same single object argument apart from populated fields. I've got something like this so far:

function returnNewFunc<TArg extends { b?: string }>(
  initialFunc: (arg: TArg) => void
) {
  const newFunc = (arg: Omit<TArg, "b">) =>
    initialFunc({ ...arg, b: "hello" });

  return newFunc
}

const funcA = ({ b, c }: { b: string; c: string }) => {
  console.log(b, c);
};
const funcB = returnNewFunc(funcA)
funcB({c: "test"}) // funcB should have 'c' as the only field in its argument

The issue here is I get a could be instantiated with a different subtype of constraint typescript error, so I must be doing something wrong.

about 4 years ago · Santiago Trujillo
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