Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda