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

140
Visualizações
TS how can I this function write to a arrow function?

How can I write this generic function with a arrow function ?

function simpleState<T>(initial: T): [() => T, (v: T) => void] {
  let value: T = initial;
  return [
    () => value,
    (v: T) => {
      value = v;
    }
  ]
};
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

const simpleState = <T>(initial: T): [() => T, (v: T) => void] => {
  // same function body as before
}

Since you tagged react-native, be aware that in a .tsx file, this will probably not work, since the <T> will be parsed as being a JSX tag. You can either put it in a .ts file, and import it into a .tsx file, or use one of the following workarounds to get it to not be interpreted as a JSX element.

Trailing comma:

<T,>(initial: T): // etc

Extend from unknown:

<T extends unknown>(initial: T): // etc
about 4 years ago · Juan Pablo Isaza Relatório

0

const simpleState2 = <T>(initial: T): [() => T, (v: T) => void] => {
  let value: T = initial;
  return [
    () => value,
    (v: T) => {
      value = v;
    },
  ];
}
about 4 years ago · Juan Pablo Isaza Relatório
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