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

106
Visualizações
Define type to array behavior

I need to crate a type that can hold an array where each element is a function that gets the previous output as an input. For example, a valid array is:

const pipe: SpecialArray = [
    () => string,
    (prev:string) => number,
    (prev:number) => boolean
];

An invalid array would be:

const pipe: SpecialArray = [
    () => string,
    (prev:number) => number, // <-- Here number should be string
    (prev:number) => boolean
];

Is there a way to define such structure in TypeScript?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I believe no, since Array is homogenous, you'll have to define in the form [(a: string) => number, (b: number) => boolean], and you can't really enumerate all (unless a code generator is used).

about 4 years ago · Juan Pablo Isaza Relatório

0

It is impossible in TypeScript to create standalone type for such kind of array. In order to do that you should create compose function, infer each function from arguments and validate it. Please see my article and questions/answers on SO: first , second, third.

Also you can check this compose function in fnts lib

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